Display alternate image

前端 未结 4 844
遇见更好的自我
遇见更好的自我 2021-01-04 01:02

Is it possible to show an alternate image if the original source file is not found? I would like to achieve this only with css and html, no javascript (or jQuery and alike).

4条回答
  •  旧时难觅i
    2021-01-04 01:29

    yes, you can do it by using only html, when img src not found then it will throw error so here we can handle it. One more point is set this.onerror = null for recursive calling (default image not found)

    User Image
    

提交回复
热议问题