javascript 单击 HTML 页面中的图像时弹出窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29382121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 10:27:10  来源:igfitidea点击:

Pop-up window when clicking on an image in my HTML page

javascripthtml

提问by MD-4

I know this question has been asked before, but mine is a little different.

我知道以前有人问过这个问题,但我的有点不同。

I know tthat to do a popup of a thumbnail i have to use Javascript and give te image location. however, what i want to do is this;

我知道要弹出缩略图,我必须使用 Javascript 并提供图像位置。然而,我想做的是这个;

<IMG SRC="test.png" ALT="test1" WIDTH=32 HEIGHT=32 onclick="openWin(test.png)"></a> 

where test.PNG is a picture i just queried from the database in SQLPLUS. i do not have a local copy and i do not know the path to id. when i write the javascript function for this, i wrote:

其中 test.PNG 是我刚刚从 SQLPLUS 中的数据库查询的图片。我没有本地副本,也不知道 id 的路径。当我为此编写 javascript 函数时,我写道:

<script language="JavaScript">

function openWin(img) {
    window.open(img);

}
</script>

however, i keep getting a URL\image.png does not exist. How can i get this working? it has to work for an arbitrary number of images, depending on how many actually meet the requirements of the query.

但是,我不断收到不存在的 URL\image.png。我怎样才能让它工作?它必须适用于任意数量的图像,具体取决于实际满足查询要求的图像数量。

the test.png does not actually exist, i wanted to see becuase it shows as a broken image icon in my table, but when i click on it, it says the URL does not exist.

test.png 实际上并不存在,我想看到它,因为它在我的表格中显示为一个损坏的图像图标,但是当我点击它时,它说 URL 不存在。

回答by Miss Cat

Screw Javascript. You don't need Javascript for this. Lose the 'onclick' and put 'target="_Blank"' in an 'href' tag around the 'img' tag.

螺丝Javascript。为此,您不需要 Javascript。去掉 'onclick' 并将 'target="_Blank"' 放在 'img' 标签周围的 'href' 标签中。

Example:

例子:

<a href="YourLink" target="_Blank">
    <img src="test.png" alt="Put something more exciting here." width="32" height="32" />
</a>

All good? By the way, this isn't PHP, my friend. Hehe. Wrong hashtag.

都好?顺便说一下,这不是 PHP,我的朋友。呵呵。错误的标签。