admin管理员组

文章数量:1401171

I am trying to open another image when I press the image button - I am pletely 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

I am trying to open another image when I press the image button - I am pletely 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

Share Improve this question edited Dec 23, 2013 at 21:17 Gabriele Petrioli 196k34 gold badges271 silver badges328 bronze badges asked Dec 17, 2013 at 14:24 NiharNihar 5512 gold badges10 silver badges29 bronze badges 2
  • 1 How do you want to display the 2nd image? In the same place as the first? Or maybe inside something like a lightbox? – RienNeVaPlu͢s Commented Dec 17, 2013 at 14:27
  • Why not simply <a href="img/floor.jpg"><img src="img/gallery/5.jpg" /></a>? – Reeno Commented Dec 17, 2013 at 14:29
Add a ment  | 

2 Answers 2

Reset to default 5

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;"

本文标签: javascriptHow to open an image by clicking the image buttonStack Overflow