javascript中writeln和write的区别是什么-LMLPHP

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

javascript提供了两种方式来在浏览器中直接显示数据。可以使用 write( ) 和 writeln( ),这两个函数是document 对象的方法。

writeln( ) 方法与 write( ) 方法几乎一样,差别仅在于是Write不能够换行,Writeln能够换行。

writeln( ) 将在所提供的任何字符串后添加一个换行符。而write()方法不会在字符串末尾添加一个换行符。

注:在网页中是看不到writeln的换行效果的,它是被浏览器表现为一个空格显示出来了。

javascript中writeln和write的区别是什么-LMLPHP

在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>
登录后复制

而后在弹出的窗口中查看网页源文件,就可看到效果。

【相关推荐:javascript学习教程

以上就是javascript中writeln和write的区别是什么的详细内容,更多请关注Work网其它相关文章!

09-12 00:10