] tag, The code is [document.write("First line
Second line")]."/>
] tag, The code is [document.write("First line
Second line")].">
Home > Article > Web Front-end > How to wrap lines in js
Methods to implement line breaks in js: 1. Use line breaks [\n, \r], the code is [alert("first line\n second line")]; 2. Use HTML [ 0c6dc11e160d3b678d68754cc175188a】 tag, the code is [document.write("First line, second line")].
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, DELL G3 computer. This method is suitable for all brands of computers.
Methods to implement line breaks in js:
Method 1: Use line breaks
1, \n
Line break
In JavaScript, we can use \n directly where we want to break a line:
<script> alert("第一行\n第二行"); </script>
2, \r
Line break
<script> alert("第一行\r第二行"); </script>
Method 2: Use HTML’s 0c6dc11e160d3b678d68754cc175188a
tag
When content can be written to an HTML document, you can use HTML’s 2a87851f231f0546ed00aa1a4409038e tag to perform line breaks.
Example: Use document.write()
<script> document.write("第一行<br>第二行") </script>
Output:
第一行 第二行
Related free learning recommendations: javascript learning tutorial
The above is the detailed content of How to wrap lines in js. For more information, please follow other related articles on the PHP Chinese website!