如何使用图像的类名在新窗口中打开图像



我想在新窗口中打开图像,但我无法理解JavaScript代码!

HTML:

<img class="picture" onclick="expand()" src="bild1.jpg">

Javascript:

function expand()
{   
var bigImage = document.getElementByClassName('picture');
var source=bigImage.getAttribute('src');
window.open(source)             
}

target属性指定打开链接文档的位置。。

您可以在锚点元素中使用您的图像。

<a target="_blank" href="yourimage.jpg"><img class="picture" src="yourimage.jpg"></a>

您不需要JS代码

target="_blank"属性添加到链接中,即可在新窗口中打开它们,无需javascript。

<a href="bild1.jpg" target="_blank"><img class="picture"  src="bild1.jpg"></a>

最新更新