使用图像和标题使JavaScript onclick函数打开模式

使用图像和标题使JavaScript onclick函数打开模式,javascript,jquery,html,Javascript,Jquery,Html,我现在有它,所以一旦点击模式打开,但它不显示图像。。 这是密码 HTML JavaScript showImage函数应采用以下参数: // 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 = document.getElementById('

我现在有它,所以一旦点击模式打开,但它不显示图像。。 这是密码 HTML

JavaScript

showImage函数应采用以下参数:

// 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 = document.getElementById('myImg');
var modalImg = document.getElementById("image");
var captionText = document.getElementById("caption");
function showImage(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
function showImage(image){
然后将模态图像src设置为该参数:

// 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 = document.getElementById('myImg');
var modalImg = document.getElementById("image");
var captionText = document.getElementById("caption");
function showImage(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
function showImage(image){