我有一堆圖片,點擊後會打開一個彈出框,其中包含關於所選圖片的信息,但所有彈出框同時打開。 開始,我有一些彈出框同時打開
<ul class="cenas_top">
<li>
<div class="shape">
<a href="#ef" class="overlay round"></a>
<div class="details">
<span class="heading">Direção</span>
<hr />
<!-- Trigger/Open The Modal -->
<button id="myBtn">Mais</button>
</div>
<div class="bg"></div>
<div class="base">
<img src=" alt="" />
</div>
</div>
<h3>Name</h3>
</li>
<li>
<div class="shape">
<a href="#fc" class="overlay round"></a>
<div class="details">
<span class="heading">Direção</span>
<hr />
<!-- Trigger/Open The Modal -->
<button id="myBtn">Mais</button>
</div>
<div class="bg"></div>
<div class="base">
<img src=" alt="" />
</div>
</div>
<h3>Name</h3>
</li>
</ul>
然後,我有框:
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content-->
<div class="modal-content" id="ef">
<div class="modal-header">
<span class="close">×</span>
<h2></h2>
</div>
<div class="modal-body">
<p>TEXT TEXT TEXT TEXT</p>
</div>
<div class="modal-footer">
</div>
</div>
<!-- Modal content-->
<div class="modal-content" id="fc">
<div class="modal-header">
<span class="close">×</span>
<h2></h2>
</div>
<div class="modal-body">
<p>TEXT TEXT TEXT TEXT</p>
</div>
<div class="modal-footer">
</div>
</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>
缺少了什麼嗎?
你能提供一個工作的例子嗎? –
@AnnaJeanine這裏的工作示例: [鏈接](http://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal2) –