모달창 10개 만들기,,,

모달창 10개 만들기,,,

QA

모달창 10개 만들기,,,

답변 2

본문

<!-- 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

같은 코드를 10개 넣는다면 아주 뭐같은 일이겠죠? ㅋ

50개라면? ㅋ

 

모달코드를  별도 파일로하고 클릭시에만 불러오는 .load() 이런 방식으로 하세요

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
  • 질문이 없습니다.
전체 0
© SIRSOFT
현재 페이지 제일 처음으로