<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>如何用javascript JQuery 判断图片是否存在</title>
<script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body>
<div>
<img src="https://www.zhengdecai.com/zb_users/upload/2013/4/201304091007585418.png" />
<img src="https://www.zhengdecai.com/1.png" />
<img src="https://www.zhengdecai.com/2.png" />
<img src="https://www.zhengdecai.com/3.png" />
<img src="https://www.zhengdecai.com/4.png" />
</div>
<div id="msgTool">
</div>
<script language="javascript" type="text/javascript">
$(function (){
$("img").each(function (i,e){
var imgsrc = $(e).attr("src");
$(e).load(function(){
$("<p> ok "+ $(e).width()+":"+$(e).height()+"</p>").appendTo("#msgTool");
}).error(function() {
$("<p> error "+ imgsrc +"</p>").appendTo("#msgTool");
$(e).attr("src","默认图片地址");
}) ;
});
});
</script>
</body>
</html>
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。