Second line")"."> How to break new lines in JavaScript-JS Tutorial-php.cn

How to break new lines in JavaScript

coldplay.xixi
Release: 2023-02-17 15:38:32
Original
26056 people have browsed it

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.

How to break new lines in JavaScript

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,\nLine break character

In JavaScript, we can use \n directly where we want to break a line:

Copy after login

2,\rLine break

Copy after login

The above two methods have the same results:

How to break new lines in JavaScript

##Method 2: Use HTML
tag

When you can write content into an HTML document, you can use HTML's
tag to wrap lines.

Example: Use

document.write()

Copy after login

Output:

第一行 第二行
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!