In the project will inevitably use the picture, especially the list, sometimes the picture will fail to load, it will show a hard to see the bad picture thumbnail, the following two methods to solve the problem:
1. If you have introduced a jquery plugin in your project, you can use the error ([[DATA],FN]) function;
$ ("img"). Error (function() {//) the action you want to take when the picture fails to load
$ (this). attr (' src ', ' images/no_pic.jpg ');});
2, if the project does not have a plug-in such as jquery, you can use the HTML DOM event onerror event processing;
in HTML: <element onerror= "MyScript" > Try It
In JavaScript: object.onerror=function() {myScript}; try it.
JavaScript, use the AddEventListener () method: (Note: Internet Explorer 8 and earlier versions of IE do not support the AddEventListener () method.) ) Object.addeventlistener ("error", MyScript);
Supported HTML Tags: , <input type= "image";, <object>, <script>, <style>
JS Picture loading Failure Processing method