<html>
<script>  
  function fuc() {
      document.write("good!");//web页面中只有一个“good!”,为什么每次都清除以前的内容再写入?
      //document.body.innerHTML=Math.random();这条语句能生成随机数说明setTimeout执行良好
      setTimeout("fuc()",1000);
  }
</script>
<body onload="fuc();">
</body>
</html>

解决方案 »

  1.   

    你误会了
    其实load完之后 你调用的func其实是没有write操作的
      

  2.   

    当页面加载完毕后运行 fuc() 之后,页面就成这样了
    <html>
    <head></head>
    <body>good!</body>
    </html>
      

  3.   

    你的意思是执行万func后,js函数就不存在了?
      

  4.   

    页面加载完成之后,运行document.write()会把原来的页面清空并重写。。
      

  5.   

    document.write方法在你之后调用setTimeout("fuc()",1000);时,已经不能起作用了
    原因在于你之后调用的时候,page已经加载完毕了
      

  6.   

    哦?那你能告诉我<html>
    <head>
    </head>
    <body>
    <p>This is a page.</p>
    <script>
    window.onload = function(){
    document.write('<p>This is another page.</p>');
    }
    </script>
    </body>
    </html><html>
    <head>
    </head>
    <body>
    <p>This is a page.</p>
    <script>
    document.write('<p>This is another page.</p>');
    </script>
    </body>
    </html>是怎么回事吗,大侠?
      

  7.   


    你这个例子如何和你的描述是一个意思,那我向你道歉。
    我对文字的理解始终都有误区,之前经常犯类似的错误
    不过我觉得如果这样说的话可以解释:
    如果一个事件处理程序调用document.write,且文档已解析完毕,该处理程序被调用时,结果会被覆盖。
      

  8.   

    这一点,chromium并不这么理解。
      

  9.   

    最好的方法是通过append或者html+的方式
      

  10.   

    <html>
    <script>
      function $(o){return document.getElementById(o)}
      function fuc() {
          //document.write("good!");//web页面中只有一个“good!”,为什么每次都清除以前的内容再写入?
          //document.body.innerHTML=Math.random();这条语句能生成随机数说明setTimeout执行良好
      $('test').innerHTML += 'good!';
          setTimeout("fuc()",1000);
      }
    </script>
    <body onload="fuc();" id="test">
    </body>
    </html>这样。
      

  11.   

    把document.write放在<body>且不要放在window.onload里面就行,或者用appendChild,请别一贴多用,果断给分,谢谢
      

  12.   

    再问一个问题,帖子加到100分,呵呵。
    document.write()和document.writeln() 我试验过根本没区别啊,后者多输出一个换行符,可是换行符在html中会被忽略的啊我的理解有误吗?
      

  13.   

    你的理解没错,不过浏览器并不是任何情况下都忽略换行符的,比如在标签<pre>里面
      

  14.   

    你的理解没错,不过浏览器并不是任何情况下都忽略换行符的,比如在标签<pre>里面,给个例子就很明了了<html>
    <head>
    </head>
    <body>
    <p>This is a page.</p>
    <script>
    document.writeln('<pre>one');
    document.write('two');
    document.writeln('three');
    document.writeln('</pre>');
    </script>
    </body>
    </html>