//图片加载失败处理
jQuery('img').each(function(){
var error = false;
if (!this.complete) {//加载未成功
error = true;
}
if (typeof this.naturalWidth != "undefined" && this.naturalWidth == 0) {//判断图片原始尺寸失败
error = true;
}
if(error){//出错处理
$(this).bind('error.replaceSrc',function(){
this.src = "http://file.do.yy.com/group1/M02/01/A9/tz0MDVIghNCAaMnsAAAVHpUv0s4430.png";
$(this).unbind('error.replaceSrc');
}).trigger('load');
}
});
本文介绍了一种使用jQuery处理网页中图片加载失败的方法。通过遍历页面上的所有图片元素并检查其加载状态,一旦发现加载失败的图片,则自动替换为备用图片资源。
7568

被折叠的 条评论
为什么被折叠?



