代码示例:(标识:jsck_confirm_2)
<!DOCTYPE html>
<html>
<body>

<h1>Window 对象</h1>

<h2>confirm() 方法</h2>

<p>单击该按钮可在确认框中查看换行符。</p>

<button onclick="myFunction()">试一试</button>

<p id="demo"></p>

<script>
function myFunction() {
  let text = "请按按钮!\n确认或取消。";
  if (confirm(text) == true) {
    text = "您按了确认!";
  } else {
    text = "您按了取消!";
  }
  document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>
运行结果: