如果图片加载失败,浏览器会抛出404错误,怎么处理这种问题。var imgObj = new Image();
imgObj.src = imgURL;
imgObj.onerror = function (){
console.log("404");
$('body').css('background', 'url('+ 默认图片 +')repeat-x #fff');
};
imgObj.onload = function (){
$('body').css('background', 'url('+ imgURL+')repeat-x #fff');
};
添加回答
举报
0/150
提交
取消