Change image source with JavaScript

后端 未结 13 1893
我寻月下人不归
我寻月下人不归 2020-11-27 18:20

So I\'m new with JavaScript (this is actually my first attempt to make something work) and I\'m having a bit of trouble. I thought I had enough knowledge to make this work,

13条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 19:17

    You've got a few changes (this assumes you indeed still want to change the image with an ID of IMG, if not use Shadow Wizard's solution).

    Remove a.src and replace with a:

    
    

    Change your onclick attributes to include a string of the new image source instead of a literal:

    onclick='changeImage( "1772031_29_b.jpg" );'
    

提交回复
热议问题