一般的解释是document.writeln会在字符串后面添加一个换行符(\n)为什么我测试页面时发现2者是一样的效果呢,document.writeln也没有给字符串后面添加换行符(\n)...

解决方案 »

  1.   


    document.write()和document.writeln都是JavaScript向客户端写入的方法writeln是以行方式输出的,一般情况下用两种方法输出的效果在页面上是没有区别的,两种方法仅当在查看源代码时才看得出区别,除非是输出到pre或xmp元素内测试一下:<script> 
    with(window.open()){ 
    document.write("百度")
    document.write("百度")
    document.writeln("知道")
    document.writeln("知道")
    document.writeln("知道")

    </script>运行上面的代码,在新开的窗口中:查看-源文件,就可以看到,writeln是以行方式输出关于保留格式,测试一下:<script> 
    document.write("<pre>百度")
    document.write("百度")
    document.writeln("知道")
    document.writeln("知道")
    document.writeln("知道</pre>") 
    </script> 
      

  2.   

    你可能是用的inner.html
    用inner.text试试
      

  3.   

    document.writeln("aaa");
    document.write("aaa\n");
    这两个等价
    至于为什么没换行,在html中换行符号是<br>,\n是字符串的换行符
      

  4.   

    上面都说了。我再蹭点分<script> 
    document.writeln("<textarea>百度")
    document.writeln("百度")
    document.write("知道1")
    document.writeln("知道2")
    document.write("知道</textarea>") 
    </script> 
      

  5.   

    zswang说了:哥缺的不是分,个缺的是寂寞