强制用户单击 'OK' 选项进行确认

Force user to click 'OK' option in confirm

我不知道有没有选择,但我想知道有没有可能。

我想使用"confirm"命令,但我想弹出确认window直到用户点击"OK",而不是"Cancel"。

诶?您实际上可以检查 confirm 的输出,这是一个布尔值并按照...

if (confirm("Are you sure?"))
  // Add code here to do what when user clicks Okay.
  alert("You clicked okay!");
else
  // Add code here to do what when user clicks Cancel.
  alert("You clicked cancel!");

  • 好的: true
  • 取消: false

像这样把它放在一个 while 循环中:

while(!confirm("By clicking OK below, you agree to sell me your soul.")) {}