<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
이런식으로 모달창 만들려고 하는데요.
버튼하고 열리는 창이 각각 10개 씩 필요합니다.
그걸 만드는건 어렵지 않은데, 아래 스크립트에서 각 10개마다 따로 작동하게 할려면 하드코딩으로 해야 하나요? id만 다르게 해서 function(#id){} 이런식으로 들어가게 할려면 어떻게 해야 하나요.
답변 2개
답변을 작성하려면 로그인이 필요합니다.