Home > Article > Web Front-end > What is the difference between writeln and write in javascript
The difference between writeln and write in javascript: When the writeln() method outputs data in the browser, it will add a newline character at the end of the data for line break; while the write() method outputs data in the browser , does not add a newline character at the end of the data, and therefore cannot wrap.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript provides two ways to display data directly in the browser. You can use write( ) and writeln( ), which are methods of the document object.
The writeln( ) method is almost the same as the write( ) method. The only difference is that Write cannot wrap, but Writeln can wrap.
writeln( ) will add a newline character after any string provided. The write() method does not add a newline character to the end of the string.
Note: The line breaking effect of writeln cannot be seen on the web page. It is displayed as a space by the browser.
The effect cannot be seen in the HTML file and the JSP source file. Readers can add pre-formatted tags to the tags to view the effect. Browser
<script> document.write("<pre class="brush:php;toolbar:false">write"); document.writeln("writln"); document.write("write");
You can also use the open method to re-open a window to view the test
<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.
[Related recommendations: javascript learning tutorial]
The above is the detailed content of What is the difference between writeln and write in javascript. For more information, please follow other related articles on the PHP Chinese website!