开发者

What is the difference between “document.write(‘hello world\n’);” and “document.writeln(‘hello world’);”?

What is the difference between doc开发者_JAVA百科ument.write(‘hello world\n’); and document.writeln(‘hello world’);?

Edit

My question is what will be the difference of output.


Historically, writeln was intended to handle different newline conventions, of with \n is only one.

There are different conventions for end-of-line. '\n' is the end-of-line marker on UNIX, '\r' on Mac (AFAIK not any more as it's now a UNIX) and '\r\n' is DOS/Windows. Using writeln should automatically use the correct one on the desired platform in other languages, but I don't really know whether JavaScript's document.writeln automatically uses the correct one automagically.


The writeln() method is identical to the write() method, with the addition of writing a newline character after each statement.

from w3schools.com

edit: for the sake of completeness :)

writeln on mozilla.org

writeln on w3.org


In theory, writeln() appends a line feed to the end of your string.

In practice, since you're talking Javascript, there's little real difference if you're generating HTML, since HTML ignores extra white space anyway.


afaik there's no difference between them. You'll end up with a line, which has a "new-line-sign" at the end, so the next text youre gonna display will show up in the following line.

if this is a tricky question sorry for my ignorance:)


document.write() writes to the document without appending a newline on the end. document.writeln() writes to the document appending a newline at the end.


Lets take this is as an example:

Out put for write(): Hello World!Have a nice day!

Note that write() does NOT add a new line after each statement.

Output for writeln(): Hello World! Have a nice day!

Note that writeln() add a new line after each statement.


document.write you will get the courser in the same line, but in document.writeln you will get the courser in the next line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜