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>
打赏

本文固定链接: https://www.cxy163.net/archives/4388 | 绝缘体

该日志由 绝缘体.. 于 2013年05月23日 发表在 go, html, javascript, PHP, 编程语言 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: Jquery判断图片是否加载失败 | 绝缘体
关键字: , , , ,

Jquery判断图片是否加载失败:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter