jQuery/JavaScript to replace broken images

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

    Handle the onError event for the image to reassign its source using JavaScript:

    function imgError(image) {
        image.onerror = "";
        image.src = "/images/noimage.gif";
        return true;
    }
    
    
    

    Or without a JavaScript function:

    
    

    The following compatibility table lists the browsers that support the error facility:

    http://www.quirksmode.org/dom/events/error.html

提交回复
热议问题