javascript - 无法使用下拉列表中的图像打开新窗口
问题描述
我是 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>
解决方案
改变
myWindow.document.write("<img src='selection' width='85' height='95' />");
到 myWindow.document.write("");
推荐阅读
- spring-boot - 作为集成测试的一部分运行外部 Spring Boot 应用程序
- powershell - Ansible - 使用 powershell 跳过不存在的 ansible 变量的条件
- google-cloud-platform - 是否可以重新分配我在 Google Cloud Platform 上的组织电子邮件中的 5 TB 空间?
- jenkins - 如何从触发的作业中获取内部版本号
- r - 使用“across”更改 dplyr 中的多个列
- visual-studio - Visual Studio 2019 未在解决方案资源管理器中的解决方案下显示项目
- javascript - 关于cloneNode和insertBefore使用的问题
- mongodb - 在 CosmosDB(Mongo API)中创建链接(参考)文档的数据建模问题
- python - 如何将 python xgboost 模型转换为 spark xgboost 模型?
- android - Flutter Android Release Build CRASH - FirebaseCore Initialize App 问题