一般浏览器会报$().on()或者$().bind() is not a function的错误
后来上网查了查, 发现这个代码蛮好用的, 测试通过
$("img").each(function () {
let err = !1;
if (!this.complete) {
err = true;
}
if (typeof this.naturalWidth != 'undefined' && this.naturalWidth == 0) {
err = true;
}
if (err) {
$(this).bind('error.replaceSrc', function () {
this.src = '/assets/img/img15.gif';
$(this).unbind('error.replaceSrc');
}).trigger('load');
}
});这里面的jquery的unbind()可以防止图片出错恢复之后一闪一闪的不断的被bind执行下去。