document.writeln()

本页内容
上一节: Met_doc_write

HTML DOM writeln() 方法

Document 对象

定义和用法

writeln() 方法与 write() 方法作用相同,外加可在每个表达式后写一个换行符。

语法

document.writeln(exp1,exp2,exp3,...)
参数 描述
exp1,exp2,exp3,... 可选.要写入的输出流。它们将按顺序被追加到文档中。

浏览器支持

所有主要浏览器都支持 writeln() 方法

write()和writeln()之间的差异:


示例

<html>

<body>

<p>Note that write() does NOT add a new line after each statement:</p>

<pre>

<script>

document.write("Hello World!");

document.write("Have a nice day!");

</script>

</pre>

<p>Note that writeln() add a new line after each statement:</p>

<pre>

<script>

document.writeln("Hello World!");

document.writeln("Have a nice day!");

</script>

</pre>

</body>

</html>

Document 对象

上一节: Met_doc_write
此页面最后编辑于2022年8月19日 (星期五) 11:22。