How to express line breaks: 1. Line break character "\n", insert "\n" directly where you want a line break; 2. Line break character "\r", insert it directly where you want a line break. Insert "\r" for line break; 3. "
" tag. When writing content into an HTML document, you can insert the "
" tag where you want to break the line.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to express line breaks in javascript
1. Line break character “\n”
In JavaScript, we can use \n
directly where we want to wrap the line:
<script> alert("第一行\n第二行"); </script>
Output result:
2. Line break character "\r"
You can also use \r
directly where you want to break the line:
<script type="text/javascript"> alert("hello\rworld"); </script>
Output results :
3. HTML
tag
can be used when content can be written to the HTML document. HTML's
tag to break lines.
Example: Use document.write() or innerHTML attribute
<p id="p"></p> <script type="text/javascript"> document.getElementById("p").innerHTML="hello<br>world"; document.write("第一行<br>第二行"); </script>
Output result:
##[Recommended learning:javascript Advanced Tutorial】
The above is the detailed content of How to express line break in javascript. For more information, please follow other related articles on the PHP Chinese website!