jQuery/JavaScript to replace broken images

后端 未结 30 2512
我寻月下人不归
我寻月下人不归 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:02

    In case someone like me, tries to attach the error event to a dynamic HTML img tag, I'd like to point out that, there is a catch:

    Apparently img error events don't bubble in most browsers, contrary to what the standard says.

    So, something like the following will not work:

    $(document).on('error', 'img', function () { ... })
    

    Hope this will be helpful to someone else. I wish I had seen this here in this thread. But, I didn't. So, I am adding it

提交回复
热议问题