You're trying to get an element by id
but you haven't add an id
to your element.(您正在尝试通过id
获取元素,但尚未向其元素添加id
。)
You should use document.getElementsByName("showImage");
(您应该使用document.getElementsByName("showImage");
)
If it doesn't work it is because your image must not be in the same folder as your js file.(如果它不起作用,那是因为您的图像不得与js文件位于同一文件夹中。) The below example works.(以下示例有效。) I just replaced with an online image.(我只是替换为在线图像。)
function displayImage(item) { switch (item) { case "pizza": document.getElementById("showImage").src = "https://images.unsplash.com/photo-1496518908709-02b67989c265?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80"; } }
<h2>Main Course</h2> <ul> <li onmouseover="displayImage('pizza')">Pizza</li> <li></li> </ul> <div id="description"> <iframe width="100%" height="415px" id="showImage" /></iframe> </div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…