Second line")"."/> Second line")".">
Home >Web Front-end >JS Tutorial >How to break new lines in JavaScript
How to break lines in js: 1. Use the [\n] line break character, the code is [alert("First line\nSecond line")]; 2. Use the [\r] line break character, The code is [alert("first line\rsecond line")]; 3. Use the HTML [
] tag.
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Methods for line breaks in JavaScript:
Method 1: Use line breaks
1, \n
Line break character
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>
The above two methods have the same results:
##Method 2: Use HTML
tag
document.write()
<script> document.write("第一行<br>第二行") </script>Output:
第一行 第二行
Related free learning recommendations:javascript(video)
The above is the detailed content of How to break new lines in JavaScript. For more information, please follow other related articles on the PHP Chinese website!