More examples below.
The writeln()
method writes directly to an open (HTML) document stream.
The writeln()
method is identical to the write() method, with the addition of writing a newline character (U+000A) after each statement.
The writeln()
method deletes all existing HTML when used on a loaded document.
The writeln()
method cannot be used in XHTML or XML.
document.writeln(
exp1, exp2, ..., expN)
Parameter | Description |
exp1,... | Optional. The output stream. Multiple arguments are appended to the document in order of occurrence. |
NONE |
writeln() adds a newline character after each statement. write() does not.
document.write("Hello World!");
document.write("Have a nice day!");
document.write("<br>");
document.writeln("Hello World!");
document.writeln("Have a nice day!");
Try it Yourself »
It makes no sense to use writeln() in HTML.
It is only useful when writing to text documents (type=".txt").
Newline characters are ignored in HTML.
If you want new lines in HTML, you must use paragraphs or <br>:
document.write("Hello World!");
document.write("<br>");
document.write("Have a nice day!");
Try it Yourself »
document.write("<p>Hello World!</p>");
document.write("<p>Have a nice day!</p>");
Try it Yourself »
document.write
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!