error

UK[ˈerə(r)] US[ˈɛrɚ]

n. Error, negligence; [Law] mistrial, violation of law; [Number] error

jquery error() method syntax

Function: When an element encounters an error (not loaded correctly), an error event occurs. The error() method triggers an error event, or specifies a function to run when an error event occurs. This method is a shorthand for bind('error', handler).

Trigger the error event syntax: $(selector).error()

##Bind the function to the error event syntax: $ (selector).error(function)

Parameters:

##Parametersfunction

jquery error() method example

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("img").error(function(){
    $("img").replaceWith("<p><b>图片未加载!</b></p>");
  });
});
</script>
</head>
<body>
<img src="http://img.php.cn/upload/article/000/005/656/5af270fd37755429.jpg" />
<p>如果上面的图像没有正确地加载,会被替换为一段 "图片未加载" 的文本。</p>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Description
Optional. Specifies the function to be run when an error event occurs.