
document.write()和document.writeln都是JavaScript向客户端写入的方法
writeln是以行方式输出的,一般情况下用两种方法输出的效果在页面上是没有区别的,两种方法仅当在查看源代码时才看得出区别,除非是输出到pre或xmp元素内
测试一下:
with(window.open()){
document.write("百度")
document.write("百度")
document.writeln("知道")
document.writeln("知道")
document.writeln("知道")
}
运行上面的代码,在新开的窗口中:查看-源文件,就可以看到,writeln是以行方式输出
关于保留格式,测试一下:
document.write("
百度")document.write("百度")
document.writeln("知道")
document.writeln("知道")
document.writeln("知道
")
