📜  在自己的模态页面上打开每个图像 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:18.430000             🧑  作者: Mango

代码示例1
// Get the modal
    var modal = document.getElementById("myModal");

    // Get the image and insert it inside the modal - use its "alt" text as a caption
    // var img = $(".myImg");
    var modalImg = document.getElementById("img01");
    var captionText = document.getElementById("caption");
    function image(event)  {    
        modal.style.display = "block";
        modalImg.src = event.target.src;
        captionText.innerHTML = event.target.alt;
    }

    // Get the  element that closes the modal
    var span = document.getElementsByClassName("close")[0];

    // When the user clicks on  (x), close the modal
    span.onclick = function () {
        modal.style.display = "none";
    }