" tag. When writing content into an HTML document, you can insert the "
" tag where you want to break the line."/> " tag. When writing content into an HTML document, you can insert the "
" tag where you want to break the line.">

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

How to express line break in javascript

青灯夜游
青灯夜游Original
2021-09-16 15:44:3831736browse

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>

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>

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>

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!

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