代码示例:(标识:jsck_doc_writeln)
<!DOCTYPE html>
<html>
<body>

<h1>Document 对象</h1>

<h2>write() 和 writeln() 方法</h2>

<p>write() 不会在每条语句后添加新行 (CR)。</p>

<p>writeln() 在每条语句后添加新行 (CR)。</p>

<pre>
<script>
document.write("Hello World!");
document.write("Have a nice day!");
document.write("<br>");
document.writeln("Hello World!");
document.writeln("Have a nice day!");
</script>
</pre>

<p>在 HTML 中使用 writeln() 没有意义。</p>

<p>回车 (CR) 在 HTML 中会被忽略。</p>

</body>
</html>
运行结果: