onclick on a image to navigate to another page using Javascript

后端 未结 4 2064
刺人心
刺人心 2020-12-13 14:27

I am getting warmed up with Javascript so I am trying something on my own. I am searching for a onclick function, where I have thumbnail images in my index.html page, and wh

4条回答
  •  执念已碎
    2020-12-13 15:15

    I'd set up your HTML like so:

    bottle
    

    Then use the following code:

    
    

    That assigns an onclick event handler to every image on the page (this may not be what you want, you can limit it further if necessary) that changes the current page to the value of the images id attribute plus the .html extension. It's essentially the pure Javascript implementation of @JanPöschko's jQuery answer.

提交回复
热议问题