tag to achieve line break, code such as "document.write(" One line
Second line ")"."/> tag to achieve line break, code such as "document.write(" One line
Second line ")".">

Home  >  Article  >  Web Front-end  >  How to wrap js

How to wrap js

藏色散人
藏色散人Original
2021-03-03 10:36:0449193browse

JS line break method: 1. Use the "\n" line break character to implement line break; 2. Use the "\r" line break character to implement line break; 3. Use HTML's
tag to implement line break. The code is as follows "document.write("First line
Second line")".

How to wrap js

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

JavaScript is an advanced, interpreted, literal scripting language. It is a prototype-based, function-first language and a multi-paradigm language.

How to wrap lines in js?

Method 1: Use line breaks

1, \nLine breaks

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

<script>
alert("第一行\n第二行");
</script>

2, \r newline character

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

The above two methods have the same results:

How to wrap js

##Method 2: Use HTML< ;br> tag [Recommended learning:

js basic tutorial]

When you can write content to an HTML document, you can use HTML's
tag to perform line breaks.

Example: Using document.write()

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

Output:

第一行
第二行

The above is the detailed content of How to wrap js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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