IMG label src corresponding picture does not exist, display a default picture
The easiest way:
The code is as follows |
Copy Code |
1
|
But this method has one disadvantage, is when the default.jpg also does not exist, the webpage will die the loop.
JS Code:
The code is as follows |
Copy Code |
function Imgerror (obj) { obj.src= '/error/images/filmthum_err.gif '; Obj.onerror = null;//Control onerror event triggers only once } function imgloading (obj) { Obj.nextsibling.style.display= ' None '; obj.style.display= ' block '; } |
HTML code:
The code is as follows |
Copy Code |
<div> Loading ... </div> |
CSS code:
code is as follows |
copy code |
img { border:1px solid #CFCFCF; Overflow:hidden; height:141px; padding:2px; width:115px; Display:none; } . imgloading { border:1px solid #CFCFCF; height:141px; Overflow:hidden; padding:2px th:115px; Background:url ('/images/loading.gif ') center center no-repeat; Display:block; } |