Home >Web Front-end >JS Tutorial >The difference between Write and Writeln in JavaScript

The difference between Write and Writeln in JavaScript

阿神
阿神Original
2016-12-10 09:12:201281browse

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.

wKiom1hGI9PjhMAvAAAJwSkxZBM314.png-wh_600x-s_2253347697 (1).png

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn