<img id="img1" src="Images/000112.jpg" >function find(){
var oImg = document.getElementById('img1');
var oSrc = oImg.getAttribute('src');
if(oSrc == null || oSrc == ""){
    setTimeout(find,4000);
}
}

解决方案 »

  1.   

    <img src="adf.jpg" onload="alert('图片存在');" onerror="alert('图片不存在');">
      

  2.   

    这个例子看一下吧利用image对象的onerror事件来判断,出错则更换image对象的src为默认图片的URL。<p>第一种情况:图片存在,正常显示<br />
    <xmp>
    <img src="http://www.iecn.net/images/logo_home.gif" 
    onerror="javascript:this.src='http://www.cnlei.org/BLOG/styles/style2007/images/logo.gif'" />
    </xmp>
    <img src="http://www.iecn.net/images/logo_home.gif" onerror="javascript:this.src='http://www.cnlei.org/BLOG/styles/style2007/images/logo.gif'" /></p>
    <p>第二种情况:图片不存在,显示默认图片<br />
    <xmp>
    <img src="http://www.iecn.net/images/logo_homeAAA.gif" 
    onerror="javascript:this.src='http://www.cnlei.org/BLOG/styles/style2007/images/logo.gif'" />
    </xmp>
    <img src="http://www.iecn.net/images/logo_homeAAA.gif" onerror="javascript:this.src='http://www.cnlei.org/BLOG/styles/style2007/images/logo.gif'" /></p> 
    判断远程图片是否存在的asp技巧[ASP代码] 
    function CheckURL(byval A_strUrl)
    set XMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
    XMLHTTP.open "HEAD",A_strUrl,false
    XMLHTTP.send()
    CheckURL=(XMLHTTP.status=200)
    set XMLHTTP = nothing
    end function
    Dim imgurl
    imgurl="UploadFiles/2007829144940734.gif"
    if CheckURL(imgurl) then
    response.write "图片存在"
    else
    response.write "图片不存在"
    end if判断远程图片是否存在[js代码]{
    var oReq = new ActiveXObject("Microsoft.XMLHTTP")
    oReq.open("Get","UploadFiles/2007829144941621.gif",false);
    oReq.send();
    //alert(oReq.status)
    if(oReq.status==404)
    alert('不存在');
    else
    alert("存在")
    }
      

  3.   

    不用很复杂
    <img src="1.gif" onerror="doHide(this)" onload="this.style.display='inline'" width=348 height=446>
    <script>
    function doHide(e){
    alert(1);
    e.style.display = "none";
    setTimeout(function(){e.src = "1.gif?tmp="+Math.random();}, 4000);
    }
    </script>
      

  4.   

    <!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>