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

<h1>JavaScript 确认框</h1>


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

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

<script>
function myFunction() {
  var txt;
  if (confirm("Press a button!")) {
    txt = "您按了确定";
  } else {
    txt = "您按了取消";
  }
  document.getElementById("demo").innerHTML = txt;
}
</script>

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