最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

document.write 和writeln区别

JavaScript 有客 576浏览
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>

转载请注明:有客帮 » document.write 和writeln区别