JavaScript document.writeln line break

 JavaScript document.writeln is a similar function of document.write . It uses " line " as the output mode. If you want to output multi-line strings through document.write , you need to add some HTML line break tags. Please refer to " JavaScript document.write line break ". In fact , the document.writeln function of JavaScript itself can perform the effect of multi-line output, but simply use document.writeln to output. In the environment of many browsers, it cannot produce multi-line effects. It must be matched with the <pre> tag. effective.


JavaScript document.writeln basic syntax

document.writeln("The string content to be displayed on each line");


Please put the content of the string to be displayed in each line in the parentheses of document.writeln, and then write the output content of document.writeln in the second line... and so on, write document.writeln in a new line in the code, The effect will be displayed line by line on the web page, which is very different from the effect of document.write without line division.

JavaScript document.writeln example
<pre>
<script>
document.writeln("Welcome to Jasonseo.");
document.writeln("Have a good time.");
</script>
</pre>

<script>
document.writeln("Welcome to Jasonseo.");
document.writeln("Have a good time.");
</script>
The output of the above example is
Welcome to Jasonseo.
Have a good time.

Welcome to Jasonseo. Have a good time.
As mentioned in the first paragraph, each line of document.writeln must be wrapped in the <pre> tag to have an effect. From the comparison of examples, we can see that the first group of documents is wrapped in the two lines of document within the <pre> tag. .writeln is indeed output in two lines, the second group is not wrapped with a <pre> tag, and the output result becomes just one line.

Post a Comment

0 Comments