简体   繁体   English

如何通过单击图像按钮打开图像

[英]How to open an image by clicking the image button

I am trying to open another image when I press the image button - I am completely new to html. 当我按下图像按钮时,我正在尝试打开另一个图像 - 我是html的新手。 I heard that you need to use the onclick to get that. 我听说你需要使用onclick才能搞定。 Here it is what I am trying: 这是我正在尝试的:

input type="image" src="img/gallery/5.jpg" onclick="img/floor.jpg"

Where 5.jpg is the thumbnail view and floor.jpg is the target image (present in another directory). 其中5.jpg是缩略图视图,floor.jpg是目标图像(存在于另一个目录中)。

But the above piece of code is not working for me. 但上面的代码对我不起作用。 What is the correct approach? 什么是正确的方法?

Why this is failing ?? 为什么这会失败? i used the solution to open a number of images 我使用该解决方案打开了许多图像

 <a href="img/5.jpg"><img src="img/gallery/5.jpg"/></a> 
            <a href="img/6.jpg"><img src="img/gallery/6.jpg"/></a>
            <a href="img/7.jpg"><img src="img/gallery/7.jpg"/></a>
            <a href="img/8.jpg"><img src="img/gallery/8.jpg"/></a>
            <a href="img/9.jpg"><img src="img/gallery/9.jpg"/></a>
            <a href="img/10.jpg"><img src="img/gallery/10.jpg"/></a>

but every time it opens only the 10.jpg Help thanks 但每次只打开10.jpg帮助谢谢

Why use an input and javascript in the first place ? 为什么首先使用输入和javascript?

Just use a link 只需使用链接

<a href="img/floor.jpg"><img src="img/gallery/5.jpg"></a>

Just use a an onclick javascript event to toggle the visiblity of the second image. 只需使用onclick javascript事件切换第二个图像的可见性。

something like below. 类似下面的东西。

<input type="image" onclick="image.style.display=inline;">
<img src="../5.jpg" id="image" style="display:none;"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM