html图片加载失败时显示默认图
1.写在html标签里 ,onerror
<img src="pic.gif" onerror="javascript:this.src='/noPic.gif';" />
2.
<img src="pic.gif" onerror=="nofind();" />
function nofind(event){
var img=event.srcElement;
img.src="http://www.cnblogs.com/sys/common/image/fileoperation/icon/default.gif";
img.onerror=null; //控制不要一直跳动
}
3.(常用)// 假如默认图片也加载失败,则变成死循环. 此时可使用one()绑定事件
$(".discover_list img").one("error", function(e) {
$(this).attr("src", "images/default.png");
});
浙公网安备 33010602011771号