onerror event using background: url()

前端 未结 3 757
自闭症患者
自闭症患者 2020-12-23 20:46

Is there a way to show alternate image if source image is not found? I know to accomplish this is by doing something like below:



        
3条回答
  •  抹茶落季
    2020-12-23 21:20

    With background images, there is no event; you have check yourself.

    Make an (XML)HTTP request, and if you get a response with an error status code or no response at all (after timeout), use another image resource. This approach is limited by the Same-Origin Policy.

提交回复
热议问题