is both JavaScript output to the client, and compared the difference of writing is a ln--line or, in other words, the writeln method is based on the output, the equivalent of the? Winte? Output plus a newline

note: document.write method can be used in two ways: in in the process of the real-time web page loading script to create web content and create the new window or window with the delay the contents of the script. This method requires a string parameter, it is written in the HTML window or frame. The string parameter can be variable or value is a string expression, written content often contains HTML labeled.

to remember after loading the page, the browser will automatically shut down, the output stream. In some after any one of the current page (document.write) method will open a new output stream, it will be clear when the front net The output page content (including any change in the source document and value). Therefore, if you want to use HTML content script generation to replace the current page, it must connect to HTML content assigned to a variable. Here, use (document.write) to complete the write operation. Without clear and open a new document the flow of data, a document.write (OK.

) called on the document.write () method, the document.close method still need to explain it (). The script to the window (whether the window or other windows must be closed after the written content) output stream. At the end of a document.write script (behind) method (document.close). Must ensure that the method. Not doing so will not be able to show the image and form. Moreover, any document.write behind the call () will only add to the content of web pages, but not clear the existing content, write a new value of

concrete step:

1. opens a blank window. ()

2. writes the code to the blank window with the write method.

document.write ("Line1")
document.write ("Line1")

3. writes code to a blank window with a writeln method.

document.writeln ("Line1")
document.writeln ("Line2")


 < complete code example: 

; script> with (( {document.write ("Line1") document.write ("Line1") document.writeln ("Line1") document.writeln ("Line2") < /script>

;}; note: the two methods only when in view the source code to see the difference.
specifically hints: add the above code to the web page, and then check the source code of the pop-up window. We will see:


page effect and source code, such as graph.

<p> in particular in general, generally use two methods to the effect of the output on the page is no difference (except the output to the pre or XMP element). </p>
<p><strong> document.write (html</strong></p>
<p>) two, write a </p>
<p> page to initialize the specified location can be correctly written in the select box, but the call is written in <br /> control, document.write (don't know) will want to write the dynamic change of HTML innerHTML or outerHTML? And write HTML to display how to deal with? </p>
<p><pre> < html> as follows: </p>; < < head> /head> script; < > type=

on formatting, Test:

 < script> document.write (< pre> in my pre won't break! ") document.write (" I'm in pre will not wrap! ") document.writeln (" I'm in pre will wrap! ") document.writeln (" I'm in pre will wrap! ("document.writeln") I will wrap in the pre! < /pre> < /script> 

) "

Write Writeln

Write and the difference can not line, Writeln can wrap. How to

view Writeln

in the web page wrap effect is not to see the effect of writeln line, it is a browser for a space to show up.
in the HTML file and JSP source files can not see the effect, the reader can join in the label format tab to view the effect of


script home Xiaobian added: you can see through the F12

 in chrome < script> document.write (< pre> write; document.writeln ("writln") (document.write); write< /pre> < /script> "); 

; in addition to the above the readers can also use the open method to open a window to view

 < script> with (( {document.write (" write ") document.writeln (" writeln ") document.writeln (" write "< /script>}); 

and then view the page source file in the pop-up window, you can see the effect. After testing, no check in chrome 56.0.2924.3 pop-up window source files in this column, this time to "check" and see the effect on the Element column, a view source column is IE11 and Firefox50.0.

script home added:


 < < head> < title> document.write< /title> < script> document.write ("hello"); document.writeln ("world"); (//document.writeln) cannot wrap, but more space, the equivalent of rn document.writeln ("world"); document.write (< br/> "); document.write (" Hu "); / / the output of a button, document.write nested multiple quotes (" < input type='button'value=' I'/> button; "); < /script> < /head> < body> < /body> < /html> 

Chrome F12

Note: document.writeln note: (like document.write) does not work in XHTML documents

write and writeln in the XHTML file does not work, HTML grammar is relatively loose XHTML, which explains why no line breaks in html. point I view .

html, XHTML and XML defined:

1, html is a hypertext markup language (Hyper Text Markup Language), is the earliest written language ", but because of the time early, standard is not very good, write and write size mixed encoding standard;
2, XHTML is the upgraded version of HTML (Extensible Hyper Text Markup Language), the HTML encoding standard, more rigorous and pure, is a transitional language, HTML transition to XML
3, XML instant language; extensible markup language (Extensible Markup Language), is a cross platform language encoding, more free, free to create a label.
4, web coding is developed from html> > xhtml> > XML.

html, the difference between XHTML and XML:

1 XHTML, compared with HTML, XHTML document has a good complete layout, embodied in two aspects: A, elements must have an end tag; B,
, 2 elements must be nested; for the HTML elements and attributes, XHTML must be lowercase, because XML is strictly casesensitive, < li> and < LI> different labels; properties of
3, the value of XHTML must be in quotes;
4, XHTML does not support attribute minimization, what is the minimum attribute? Right:
(unminimized attributes) to minimize the non property
< input checked= "checked" >
: incorrect minimization (minimized attributes)
attributes < input checked>
, 5 in XHTML, the name attribute is deprecated and will be removed in a later version.

again says why web coding needs to be developed from html> > xhtml> > XML?

as saying "the early use of the HTML language, but it has three major drawbacks:


encoding is not standardized, the confusion of bloated, the need for intelligent display terminal can very good; 2,
performance and structure confusion, is not conducive to the development and maintenance of
; 3, can not use the network equipment more, such as mobile phone, PDA
HTML; therefore need to develop in order to solve this problem, so W3C has developed XHTML, XHTML is HTML to XML a bridge over the. And XML is the trend of the development of web.

This concludes the body part

This paper fixed link: | Script Home | +Copy Link

Article reprint please specify:The difference between document.write and document.writeln in JS | Script Home

You may also be interested in these articles!