HTML DOM Document writeln() 方法
更多示例見下文。
描述
writeln()
方法直接寫入到開啟的 (HTML) 文件流。
writeln()
方法與 write() 方法相同,只是在每個語句後添加了一個換行符 (U+000A)。
警告
當在已載入的文件中使用時,writeln()
方法會刪除所有現有的 HTML。
writeln()
方法不能在 XHTML 或 XML 中使用。
語法
document.writeln(exp1, exp2, ..., expN)
引數
引數 | 描述 |
exp1,... | 可選。 輸出流。 多個引數按照出現的順序附加到文件。 |
返回值
無 |
write() 與 writeln() 的區別
writeln() 在每個語句後新增一個換行符。write() 不會。
示例
document.write("Hello World!");
document.write("Have a nice day!");
document.write("<br>");
document.writeln("Hello World!");
document.writeln("Have a nice day!");
自己動手試一試 »
注意
在 HTML 中使用 writeln() 毫無意義。
它僅在寫入文字檔案 (type=".txt") 時有用。
換行符在 HTML 中會被忽略。
如果你想在 HTML 中換行,你必須使用段落或 <br>
示例
document.write("Hello World!");
document.write("<br>");
document.write("Have a nice day!");
自己動手試一試 »
document.write("<p>Hello World!</p>");
document.write("<p>Have a nice day!</p>");
自己動手試一試 »
瀏覽器支援
document.write
在所有瀏覽器中都受支援。
Chrome | Edge | Firefox | Safari | Opera | IE |
是 | 是 | 是 | 是 | 是 | 是 |