jQuery error () method
Examples
If the image element encounters an error, replace it with the text:
$ ( "Img"). Error (function () {
$ ( "Img") replaceWith ( "<p> Image Load Error </ p>!").;
});
$ ( "Img") replaceWith ( "<p> Image Load Error </ p>!").;
});
try it"
Definition and Usage
error () method in jQuery version 1.8 is discarded .
When the element encounters an error (when elements do not load properly), the occurrence of error events.
error () method triggers the error event, or when a predetermined function to run the event of error events.
Tip: This method is bind ( 'error', handler) shorthand.
grammar
Trigger the selected element error events:
$(selector).error()
尝试一下
Add the function to the error event:
$(selector).error(function)
尝试一下
参数 | 描述 |
---|---|
function | 可选。规定当 error 事件发生时运行的函数。 |