Home > Web Front-end > JS Tutorial > How to wrap lines in js

How to wrap lines in js

coldplay.xixi
Release: 2023-01-03 09:23:51
Original
20632 people have browsed it

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 [ <br>】 tag, the code is [document.write("First line, second line")].

How to wrap lines in js

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>
Copy after login

2, \rLine break

<script>
alert("第一行\r第二行");
</script>
Copy after login

Method 2: Use HTML’s <br> tag

When content can be written to an HTML document, you can use HTML’s < br> tag to perform line breaks.

Example: Use document.write()

<script>
document.write("第一行<br>第二行")
</script>
Copy after login

Output:

第一行
第二行
Copy after login

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template