setTimeout("find('" + oImg + "', '" + pic + "')",4000); 

解决方案 »

  1.   

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

  2.   


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
    var o;
            function find(oImg,pic)
            { 
                alert(oImg.src);
                var oReq = new ActiveXObject("Microsoft.XMLHTTP")
                oReq.open("Get",pic,false);
                oReq.send();
    o=oImg;
                //alert(oReq.status)
                if(oReq.status==404)
                {
                    oImg.style.display="none";
                    setTimeout("find(" + o+ ", '" + pic + "')",4000); 
                }
                else
                {
                    oImg.style.display="";
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <img src="1.jpg" onload="find(this,'00000002.jpg')" alt="" />
        </form>
    </body>
    </html>
      

  3.   

    RE:setTimeout("find('" + oImg + "', '" + pic + "')",4000); 
    --------------------------------
    这个怎么能得呢
    我的oImg是对像,你加了“''”的话就变成了文本了谢谢
      

  4.   

    RE: zjsfdxbao 
    ----------------
    你的方法也是一样提示::‘object’未定义 
      

  5.   

    RE:楼主一定要用ajax吗?
    ----------------
    这个当然不是,只要能实现我要的功能就行了
    谢谢
      

  6.   

    还不行?那试试这个
    还有你onload就表示成功了,还要去获取地址?放onerror里吧                setTimeout(function(){find(oImg, pic)},4000); 
      

  7.   

    也就是说SetTimeout只能传文本,而不能传对像
    那如果真的是这样那不是我的img都得添加一个ID
    但我不可能给我的页面的那么多个IMG控件都加上ID吧
      

  8.   

    RE:
    还不行?那试试这个 
    还有你onload就表示成功了,还要去获取地址?放onerror里吧
    ----------------------------
    我的功能是
    当前IMG已经显示一个图片了
    再去判断别一个图片是否存在,决定是否显示这个IMG
    而不是替换这个IMG
      

  9.   


    setTimeout(function(){find(oImg, pic);} ,4000); 
      

  10.   

    RE:
    我的功能是 
    当前IMG已经显示一个图片了 
    再去判断别一个图片是否存在,决定是否显示这个IMG 
    而不是替换这个IMG
    ------------------------
    看晕掉了。