<script type="text/javascript"> 
var t=0;
function T() 
{ document.open();
document.write(t);
document.close();
t++;
setTimeout("T()",1000); 

window.onload=T; 
</script>
这么短的代码都会出问题,
搞了半天不知道怎么回事,
希望高手能指点一下!!!
谢谢!!!

解决方案 »

  1.   

    document.close();
    了,代码什么的,啥都没了
      

  2.   

    错了,我查了一下,应该是document.write的问题You should not use the write or writeln methods on the current document after the document has finished loading unless you first call the open method, which clears the current document's window and erases all variables.
      

  3.   


    <script> 
    t=0;
    (function T(t) 

    v = "<script>" + arguments.callee + "(" + (t+1) + ")<\/script>";
    setTimeout(function(){
    document.open();
    document.write(v+ t);
    document.close();
    },1000); 
    } )(0);
    </script>
      

  4.   

    document.write不应该在事件中调用
    因为HTML文档加载完成以后,如果因为某个事件再触发document.write
    那么document.write会首先把原有内容全部清空
      

  5.   

    比如下面的代码,运行之后再查看网页源文件就知道什么回事了
    <html>
    <head>
        <title></title>
    </head>
    <body>
    <input id="tbTest" type="text" value="原有的内容会被清空" /><input type="button" value="document.write" onclick="Write()" /><script language="javascript" type="text/javascript">
        function Write() {
            var value = document.getElementById("tbTest").value;
            document.write(value);
        }
    </script>
    </body>
    </html>
      

  6.   

    还是不明白啊?
    在文档加载完毕以后,你不应该再使用write或者writeln方法,除非你首先调用open方法,因为它会清除当前文档的Window对象和所有的变量
    不知道我理解的对不对?
    可是我就是首先调用的open方法啊?
    就算会清除当前文档的Window对象和所有的变量,就相当于文档重新加载一次啊!
    那也应该是显示0,也不至于报错啊???
    谢谢了,还请再说的详细一点,好吗?
      

  7.   

    会不会是变量和方法都是t。而且javascript有时候都大小写不大敏感
    var t=0;
    function T() 
      

  8.   

    既然是清空了,当然连你的function T() 也会被清掉,所以报错找不到这个函数