![](/img/trans.png)
[英]How can I get my button when clicked in an window open on an image to work it is not calling the function
[英]Get the Source of an image and open in a new window when clicked
我在表格中有一系列图像,当我们点击图像时,我需要使用JavaScript或Jquery在新窗口/标签中打开它们。 由于这些图像可能会随着时间而改变,我认为获取这些图像的src属性并在新窗口中自动使用该src属性打开它们是个好主意。 这样我们就可以减少对代码的一些维护。
因为我是JavaScript的新手。 我需要帮助来弄清楚如何实现这一目标。
怎么样:
$("table tr td img").click(function() {
var src = $(this).attr("src");
window.open(
'/' + src, //change this to your relative path + src
'_blank' // <- This is what makes it open in a new window.
);
});
使用target="_blank"
作为锚标记
<a href="your-image-path" target="_blank"><img src="your-image-path"/></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.