如何在提示框中添加换行

如何在提示框中添加换行

为了在 提示框 的内容中添加换行,我们将使用 \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>
HTML

输出:

如何在提示框中添加换行

示例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>
HTML

输出:

如何在提示框中添加换行

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册