How to detect broken image and replace with another?

前端 未结 3 993
旧巷少年郎
旧巷少年郎 2021-02-10 17:35

I have a page which displays lots of images from different remote servers. http://example.com/img/email_star0.png\' height=\'150\' />

Now suppose this image is not prese

3条回答
  •  终归单人心
    2021-02-10 18:15

    Yes this is possible using onerror event:

    
    

    If the image does not exist, instead of displaying the X, this will show the default image in your local folder

提交回复
热议问题