HTML DOM writeln() 方法
Document 對象定義和用法
writeln() 方法與 write() 方法作用相同,外加可在每個表達式后寫一個換行符。
語法
document.writeln(exp1,exp2,exp3,...)
參數(shù) | 描述 |
---|---|
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>
<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 對象
更多建議: