JavaScript change img src attribute without jQuery

前端 未结 6 1826
礼貌的吻别
礼貌的吻别 2020-12-06 01:44

How to change the src attribute of a HTMLImageElement in JavaScript?

I need help to convert logo.attr(\'src\',\'img/rm2.png\')

6条回答
  •  我在风中等你
    2020-12-06 02:05

    Since you say you want to do this in different places of the program, I would create a function like this:

    function ChangeImage(image_id,path)
    {
      document.images[image_id].src = path
    }
    

提交回复
热议问题