The difference between JavaScript document.write and document.writeln
Document.write and document.writeln are both the syntax used by JavaScript to output strings. In fact, there is almost no difference between them. So why are they divided into write and writeln? Take a closer look at writeln that has more ln than write, that is, it means more line. The difference is that writeln is output in the form of " lines ". That's it. Assuming that there is a coherent string, it does not need to be divided into multiple lines. For direct output, use document.write . If you want to output multiple lines, use document.writeln .
Basic syntax of document.write and document.writeln
document.write("string to be output"); document.writeln("string to be output");
The usage of the two is almost the same, it seems that there is no difference, in fact, the effect can only be shown when the code is written.
document.write and document.writeln examples
<script language="javascript">
document.writeln("Welcome to Wibibi.");
document.writeln("Have a good time.");
document.write('Welcome to Wibibi.');
document.write('Have a good time.');
</script>
</pre>
Welcome to Wibibi.
Have a good time.
Welcome to Wibibi.Have a good time.
In fact, document.write can also output newline effects! However, you need to add some HTML line break tags, such as <br> or <p> tags, which can also achieve the effect of line breaks, and you don’t need to use <pre></pre> tag packaging. Although it is a bit troublesome, it can also be made with The same effect as document.writeln , free choice!
Post a Comment
0 Comments