error 通常用来处理图像无法加载的错误。
$("img").error(function(){
$(this).hide();
});
$(document).ready(function(){
$("img").error(function() {
$(this).attr("src","/static/img/tempImg.jpg");
});
});
如果异常是由window对象抛出,事件处理函数将会被传入三个参数:
1. 描述事件的信息 ("varName is not defined", "missing operator in expression", 等等.),
2. 包含错误的文档的完整URL
3. 异常发生的行数 如果事件处理函数返回true,则表示事件已经被处理,浏览器将认为没有异常。