首页 > 解决方案 > 无法使用下拉列表中的图像打开新窗口

问题描述

我是 web 开发的新手,我display_image(selectedImage)在头部有这个功能,我在正文中有一个选择选项。有人可以向我解释如何让选择变量从下拉列表中打开图像。

function display_image(selectedImage) {

    var selectionName = selectedImage.options[selectedImage.selectedIndex].text;
    var selection = selectedImage.options[selectedImage.selectedIndex].value;


myWindow = window.open("", "myWin", "heigth=150,width=150");

myWindow.document.open();
myWindow.document.write("<html>");
myWindow.document.write("<head>");
myWindow.document.write("<title>try this</title>");
myWindow.document.write("</head>");
myWindow.document.write("<body bgColor='grey'>");
myWindow.document.write("<center>");
myWindow.document.write("<h3>selectionName</h3>");
myWindow.document.write("<img src='selection' width='85' height='95' />");
myWindow.document.write("</center>");
myWindow.document.write("<form><input type='button' value='Close' onclick='window.close();'/> 
</form>");
myWindow.document.write("</body>");
myWindow.document.write("</html>");
myWindow.document.close(); 
myWindow.document.focus(); 
}

<select name="images" onchange="display_image(this)">
<option value=""></option>      
<option value="images2/fes.jpg">Image1</option>
<option value="images2/fes.jpg">Image2</option>      
</select>

标签: javascripthtml

解决方案


改变

myWindow.document.write("<img src='selection' width='85' height='95' />");

到 myWindow.document.write("");


推荐阅读