您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JavaScript中Write和Writeln的区别

2024/3/31 16:29:02发布150次查看
write不可以换行,writeln可以换行。
如何查看writeln的换行效果
在网页中是看不到writeln的换行效果的,它是被浏览器表现为一个空格显示出来了。
在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中都有查看源文件一栏。
注意:document.writeln (like document.write) does not work in xhtml documents
write和writeln在xhtml文件不起作用,html就是语法相对宽松的xhtml,这也就解释为什么在html没有出现换行。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product