//检查图片是否存在
function CheckImgExists(imgurl) {
var ImgObj = new Image(); //判断图片是否存在
ImgObj.src = imgurl;
//没有图片,则返回-1
if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
alert(imgurl + '存在');
} else {
alert(imgurl + '不存在');
}
}
CheckImgExists('/editor/simple/FileIconDir/rar.gif');
CheckImgExists('/editor/simple/FileIconDir/rarsdfs.gif');
========方法二====================
<p>判断百度的LOGO是否存在:<br>
<IMG src="http://www.baidu.com/img/baidu_logo.gif" onerror="javascript:this.src='/images/logo.jpg'"></p>