// 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";
}
}
HTML (Button):
<button class="buttin" id="myBtn">Terms & Conditions</button>
HTML (Pop Up Content):
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<h3 style="margin-top: 0px;"><strong>Terms and Conditions</strong></h3>
Please read the following terms and conditions before using our website.
</div>
</div>
은 commen에서 말했다,하지만 당신은 VILL 변수 홍보 ID가 필요합니다. 같은 :
var modal = document.getElementById('myModal1');
var modal2 = document.getElementById('myModal2');
전체 예를 들어 https://jsfiddle.net/3u8ummwn/2/를 참조
사용 여러 여러 팝업을 위해 ID와 여러 시간을 전화! – osyan
JS 코드에서 감사합니다. 그것은 이렇게 될 것입니다. var modal = document.getElementById ('myModal'. 'myModal1'); 그런 다음 ID가 HTML로 변경 되었습니까? – Phil
'var modal = document.getElementById ('myModal1');''id = "myModal1" '을 사용합니다. – osyan