Second line")".">
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:
2,\r
Line break
The above two methods have the same results:
##Method 2: Use HTML
tag
document.write()
第一行 第二行
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!