document.writeln后会刷新页面内容,其实已经打印出1111111了,只是load完后被刷掉而已

解决方案 »

  1.   

    建议不要用document.writeln 会改变文档结构
    你可以用document.body.innerHTML += "<p>2222222222</p>";
      

  2.   

    呃,囧啊,那为什么如下代码不会刷掉原来内容啊?document.writeln倒底有什么样的属性啊?我要疯了。
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title></head><body>
    <p>1111111111</p>
    <script type="text/javascript">
    document.writeln("2222222222");
    </script>
    </body>
    </html>
      

  3.   

    同意2楼的 用innerHTML就可以了
    都不知道原来还有writeln这东西
      

  4.   

    哪位高手可以说下innerHTML属性与writeln的细节吗?小弟狂晕中。
      

  5.   

    http://zhidao.baidu.com/question/51696717.htmlhttp://zhidao.baidu.com/question/51696717.html
    参考一下
      

  6.   

    做个空DIV往里填innerHtml,或者添加TextNode节点。
      

  7.   

    我喜欢贴官方说明:
    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.
      

  8.   

    document.body.innerHTML += " <p>2222222222 </p>";
      

  9.   


    这是很基础的问题啊。
    1, document.onload 是在DOM树被Browser加载完之后才执行的。
    2, 在onload 方法里,你调用的是 document 的writeln方法,  它回把你的整个document会被 writeln的参数 代替, 所以你看不见 你先前在页面中的所有内容(111111)
    3, 当你的script 直接嵌入在document其他位置, 如你所写的地方, Browser会从上往下处理DOM树, 所以第二种情况就会打出1111111,222222来。建议把javascript高级编程 看看