What's The Correct Way To Set Src Attribute In JQuery?

前端 未结 5 747
日久生厌
日久生厌 2020-12-15 16:07

Suppose I have the following HTML:


I would like to switch the src to bar2.jpg

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 16:26

    Just do .attr('src', 'foo') because you're assigning a src regardless. Only remove the attribute if you don't need it entirely.

提交回复
热议问题