简体   繁体   中英

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. I heard that you need to use the onclick to get that. 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).

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

Why use an input and javascript in the first place ?

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.

something like below.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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