网页图片加载失败,用默认图片替换

 $(function () {
            $('img').each(function () {
                $(this).bind('load', function () {
                    $.Deferred().resolve();
                }).bind('error', function () {
                    //图片加载错误,加入错误处理  
                    //  dfd.resolve();  
                    alert('error');
                })
            })
        })

 HTML代码

<body>
    <img src="/images/01.png" />
</body>
原文地址:https://www.cnblogs.com/sntetwt/p/4403559.html