jQuery/JavaScript to replace broken images

后端 未结 30 2513
我寻月下人不归
我寻月下人不归 2020-11-21 05:50

I have a web page that includes a bunch of images. Sometimes the image isn\'t available, so a broken image is displayed in the client\'s browser.

How do I use jQuery

30条回答
  •  名媛妹妹
    2020-11-21 06:22

    If you have inserted your img with innerHTML, like: $("div").innerHTML = , you can load another image if it fails doing, e.g, this:

    
    
    
    

    Why is javascript: _needed? Because scripts injected into the DOM via script tags in innerHTML are not run at the time they are injected, so you have to be explicit.

提交回复
热议问题