Home > Web Front-end > JS Tutorial > How to express line break in javascript

How to express line break in javascript

青灯夜游
Release: 2023-01-11 09:20:36
Original
31795 people have browsed it

How to express line breaks: 1. Line break character "\n", insert "\n" directly where you want a line break; 2. Line break character "\r", insert it directly where you want a line break. Insert "\r" for line break; 3. "
" tag. When writing content into an HTML document, you can insert the "
" tag where you want to break the line.

How to express line break in javascript

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

How to express line breaks in javascript

1. Line break character “\n”

In JavaScript, we can use \n directly where we want to wrap the line:

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

Output result:

How to express line break in javascript

2. Line break character "\r"

You can also use \r directly where you want to break the line:

<script type="text/javascript">
	alert("hello\rworld");
</script>
Copy after login

Output results :

How to express line break in javascript

3. HTML
tag

can be used when content can be written to the HTML document. HTML's
tag to break lines.

Example: Use document.write() or innerHTML attribute

<p id="p"></p>
<script type="text/javascript">
	document.getElementById("p").innerHTML="hello<br>world";
	document.write("第一行<br>第二行");
</script>
Copy after login

Output result:

How to express line break in javascript

##[Recommended learning:

javascript Advanced Tutorial

The above is the detailed content of How to express line break 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template