Write不能够换行,Writeln能够换行。html
在网页中是看不到writeln的换行效果的,它是被浏览器表现为一个空格显示出来了。chrome
在HTML文件和JSP的源文件中都看不到效果,读者能够在标签中加入预格式标签查看效果,浏览器
<script> document.write("<pre>write"); document.writeln("writln"); document.write("write</pre>"); </script>
除了上面这种读者也能够用open方法从新打开一个窗口来查看测试
<script> with(window.open()){ document.write("write") document.writeln("writeln") document.writeln("write") } </script>
而后在弹出的窗口中查看网页源文件,就可看到效果。笔者通过测试,在chrome 56.0.2924.3中的弹出窗口中没有查看源文件这一栏,这时候能够“检查”而后在Element一栏可看到效果,IE11和Firefox50.0中都有查看源文件一栏。spa
注意:.net
write和writeln在XHTML文件不起做用,HTML就是语法相对宽松的XHTML,这也就解释为何在html没有出现换行。点我查看。code
http://www.jb51.net/article/25089.htmblog
https://developer.mozilla.org/en-US/docs/Web/API/Document/writelnip
此文转载自:http://www.cnblogs.com/HDK2016/p/6135203.html