
正文
[转]js 判断图片存在
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
转自:http://blog.csdn.net/qq415734794/article/details/7261479
.//检查图片是否存在
.function CheckImgExists(imgurl) {
. var ImgObj = new Image(); //判断图片是否存在
. ImgObj.src = imgurl;
. //没有图片,则返回-1
. if (ImgObj.fileSize > || (ImgObj.width > && ImgObj.height > )) {
. alert(imgurl + '存在');
. } else {
. alert(imgurl + '不存在');
. }
.}
.
.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>





