] tag, The code is [document.write("First line
Second line")]."/> ] tag, The code is [document.write("First line
Second line")].">

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

How to wrap lines in js

coldplay.xixi
coldplay.xixiOriginal
2021-02-19 11:21:1920597browse

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 [ 0c6dc11e160d3b678d68754cc175188a】 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>

2, \rLine break

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

Method 2: Use HTML’s 0c6dc11e160d3b678d68754cc175188a tag

When content can be written to an HTML document, you can use HTML’s 2a87851f231f0546ed00aa1a4409038e tag to perform line breaks.

Example: Use document.write()

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

Output:

第一行
第二行

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!

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