首页 > 解决方案 > 如何在 HTML 中制作多行警报框

问题描述

有谁知道如何在 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.")
  }
}
<button onclick="rules()">Agree to the Rules</button>

我尝试使用<br>,但那些似乎没有在警告框中格式化。我得到的输出是这样的: 有谁知道我如何将另一行添加到警报框中?
1 行上的警报框

标签: javascripthtmlnewlinealert

解决方案


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


推荐阅读