Home >Web Front-end >JS Tutorial >The difference between Write and Writeln in JavaScript
Write cannot wrap, but Writeln can wrap.
How to check the line wrapping effect of Writeln
You cannot see the line wrapping effect of writeln on the web page. It is displayed as a space by the browser.
The effect cannot be seen in the HTML file and JSP source file. Readers can add pre-formatted tags to the tags to see the effect.
<script> document.write("<pre class="brush:php;toolbar:false">write"); document.writeln("writln"); document.write("write");
In addition to the above, readers can also use the open method to reopen a window to view
<script> with(window.open()){ document.write("write") document.writeln("writeln") document.writeln("write") } </script>
and then view the web page source file in the pop-up window to see the effect. After testing by the author, there is no view source file column in the pop-up window in chrome 56.0.2924.3. At this time, you can "check" and see the effect in the Element column. There is a view source file column in IE11 and Firefox50.0. column.
Note: document.writeln (like document.write) does not work in XHTML documents
write and writeln do not work in XHTML files. HTML is XHTML with relatively loose syntax, which explains why it does not appear in html Line break.