如何判断图像是否在html img标记中加载失败(404未找到,或其他4xx或5xx错误)并通过jquery回调报告?
答案 0 :(得分:3)
$('img').error(function(){
//...
});
来自文档的示例:
<img alt="Book" id="book" />
$('#book')
.error(function() {
alert('Handler for .error() called.')
})
.attr("src", "missing.png");