May
23
2013
Jquery判断图片是否加载失败
Jquery如何判断图片是否加载失败,下面用一个案例说明一下该问题,具体问题可根据具体情况去完善即可(下面的案例是当class为phpernote_content下的图片加载失败的时候自动去加载load_fail.png)。
JavaScript部分代码:
$(function(){
$(".phpernote_content img").each(function(){
if(this.fileSize<=0){
this.src="http://www.phpernote.com/images/load_fail.png";
}
});
});
html部分代码:
<div class="phpernote_content" >
<div><img src="http://www.phpernote.com/images/logo.gif" width="120" height="90"></div>
<div class="videoTitle">php教程</div>
</div>
<div class="phpernote_content" >
<div><img src="http://www.phpernote.com/images/logo.gif" width="120" height="90"></div>
<div class="videoTitle">javascript教程</div>
</div>
微信扫一扫,打赏作者吧~