<!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>
</head>
<script language="javascript" type="text/javascript">
    function refresh(){
location.reload();
}    function change(){
    var i = Math.round(Math.random()*1+1);
    document.write("<img src = '"+i+".jpg'>");
    setTimeout("refresh()",3000);
}

</script><body onload="change()"></body>
</html>缺少对象!

解决方案 »

  1.   

    代码确实有问题 但是缺少对象?似乎不会吧 什么浏览器测出来的不要在window.onload之后document.write 这样会覆盖文档
      

  2.   

    你是想实现隔一段时间随机换一张图片吗?
    可以用setInterval试试
      

  3.   


    <!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>
    </head>
    <script language="javascript" type="text/javascript">
        function refresh(){
            location.reload();
            }    function change(){       
            var i = Math.round(Math.random()*5+1);
    var img=document.createElement("img");
    img.src=i+".jpg";
    document.body.appendChild(img);
            //document.write("<img src = '"+i+".jpg'>");
            setTimeout("refresh()",3000);
        }
        
    </script><body onload="change()"></body>
    </html>
      

  4.   


    原因已经说出来了 是不是refresh函数被覆盖了 settime调用的时候就没了
      

  5.   

    //setTimeout("refresh()",3000);改成 setTimeout("refresh",3000);  //这个函数调用不能加括号的^_^
      

  6.   

    好像不是这样的吧…… 
    应该是如1楼和5楼说的,refresh函数在document.write的时候被覆盖了,settime调用的时候就没了
    <!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>
    </head>
    <script language="javascript" type="text/javascript">
        function refresh(){
            location.reload();
            }    function change(){
            var i = Math.round(Math.random()*1+1);
            document.getElementById("pic").src = i+".jpg";
            document.getElementById("pic").title = i+".jpg";
            setTimeout("refresh()",3000);
        }
        
    </script><body onload="change()">
    <img src="" id="pic" title="">
    </body>
    </html>
      

  7.   

    document.write 的问题都建议 不用 document.write !
      

  8.   


    实践了,实践大于理论!
    测试代码如下:<!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>
    </head>
    <script language="javascript" type="text/javascript">
        function refresh(str){
    alert(str)
        }
        function change(){        
            setTimeout("refresh(123)",1000);//可行,弹出123
            setTimeout(refresh,3000);//可行,因无参数弹出undefined
            setTimeout("refresh",5000);//压根没反应……
        }
    </script><body onload="change()"></body>
    </html>结论是6楼的代码确实不可行