모달창 10개 만들기,,,

모달창 10개 만들기,,,

QA

모달창 10개 만들기,,,

본문

<!-- 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() 이런 방식으로 하세요

 

답변을 작성하시기 전에 로그인 해주세요.
전체 123,614 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT