我想要实现的是modal_img
在modal
打开时显示。但我似乎无法弄清楚如何去做。
<img class="modal_click" src="images/4.jpg">
<div class="modal" onclick="modal_click;">
<div class="modal-content">
<span class="close">X</span>
<img class="modal_img" src="images/4.jpg">
</div>
</div>
<img class="modal_click" src="images/gandhi.jpg">
<div class="modal" onclick="modal_click;">
<div class="modal-content">
<span class="close">X</span>
<img class="modal_img" src="images/gandhi.jpg">
</div>
</div>
此时,一旦我遍历所有图像,我想更新DOM以包含正确的图像。
for(var i = 0; i < modal_click.length; i++)
{
modal_click[i].onclick = function()
{
modal.style.display = "block";
}
}
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}