如何在提示框中添加换行
为了在 提示框 的内容中添加换行,我们将使用 \n 反斜杠(n)符号。
示例1: 此示例在 提示框 的文本中的两行之间添加 \n 。
<h1 style="color:green;">
GeeksforGeeks
</h1>
<p>
Click on the button to pop
alert box with added new line.
</p>
<button onclick="gfg_Run()">
click here
</button>
<script>
var text =
"This is line 1\nThis is line 2";
function gfg_Run() {
alert(text);
}
</script>
输出:
示例2: 这个示例在文本 警报框 的3行之间添加了 \n 。
<h1 style="color:green;">
GeeksForGeeks
</h1>
<p>
Click on the button to pop
alert box with added new line.
</p>
<button onclick="gfg_Run()">
click here
</button>
<script>
var text =
"This is first line\nThis is "+
"middle line\nThis is last line";
function gfg_Run() {
alert(text);
}
</script>
输出: