转自:http://blog.csdn.net/qq415734794/article/details/7261479
01.//检查图片是否存在 02.function CheckImgExists(imgurl) { 03. var ImgObj = new Image(); //判断图片是否存在 04. ImgObj.src = imgurl; 05. //没有图片,则返回-1 06. if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) { 07. alert(imgurl + ‘存在‘); 08. } else { 09. alert(imgurl + ‘不存在‘); 10. } 11.} 12. 13.CheckImgExists(‘/editor/simple/FileIconDir/rar.gif‘);
转自:http://bbs.csdn.net/topics/290083102
<!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>
< meta
http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>无标题文档</title>
< script language="javascript"
type="text/javascript">
//载入失败调用此函数
function
defaultImg(T)
{
T.src =
"images/closelabel.gif";//默认图片地址
}
//载入成功后会调用此函数
function
LoadOK()
{
alert("LoadOK");
}
< /script>
<
/head>
< body>
<img src="123.jpg"
onerror="defaultImg(this);" onload="LoadOK()"/>
<!--123.jpg 是错误图片地址-->
< /body>
< /html>