【问题标题】:How to Make an Alert Box in HTML With Multiple Lines如何在 HTML 中制作多行警报框
【发布时间】:2019-04-05 22:29:23
【问题描述】:

有谁知道如何在 HTML 中制作一个多行的警告框?我寻找的输出是这样的:

Rules:
1. Blah Blah Blah
2. Blah Blah Blah
3. Blah Blah Blah
[Cancel]   [Ok]

这是目前在 javascript 中的代码:

function rules() {
  agree = confirm("RULES: 1. Blah Blah Blah<br> 2. Blah Blah Blah<br> 3. Blah Blah Blah<br> Press OK to agree and Cancel to Dissagree")
  if (agree == true) {
    alert("Thank you for agreeing to the rules!")
  } else {
    alert("You can not move on unless you agree to the rules.")
  }
}
&lt;button onclick="rules()"&gt;Agree to the Rules&lt;/button&gt;

我尝试使用&lt;br&gt;,但它们似乎没有在警告框中格式化。我得到的输出是这样的:

有谁知道如何在警告框中添加另一行?

【问题讨论】:

    标签: javascript html newline alert


    【解决方案1】:

    alert("这是第一行\n这是第二行\n这是第三行");

    【讨论】:

    • 考虑将您的答案格式化为 sn-p,并解释代码为何有效?
    【解决方案2】:

    插入\n会创建一个新行

    function rules() {
      agree = confirm("RULES: 1. Bl\nah Blah Blah 2. Bla\nh Blah Blah 3. Bla\nh Blah Blah Press OK to agree and Cancel to Dissagree")
      if (agree == true) {
        alert("Thank you for agreeing to the rules!")
      } else {
        alert("You can not move on unless you agree to the rules.")
      }
    }
    &lt;button onclick="rules()"&gt;Agree to the Rules&lt;/button&gt;

    【讨论】:

      【解决方案3】:

      您可以使用'\n' 来创建线条。

      例如,您的规则字符串是:

      'Rules:\n1. Blah Blah Blah\n2. Blah Blah Blah\n3. Blah Blah Blah'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-27
        • 1970-01-01
        • 1970-01-01
        • 2020-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-26
        相关资源
        最近更新 更多