Javascript警报按钮“确定”按钮

Javascript alert button OK button

本文关键字:按钮 确定 Javascript      更新时间:2023-09-26

我想问一下javascript alert button.
在我单击警报按钮上的"确定"按钮后,是否可以执行任何操作(例如:重定向,清除表单)?

您可以在警报后立即应用函数:

alert('something');//execution is halted until ok button is pressed
foo(); // calls the foo method after ok button is pressed

您可以将alert更改为使用confirm窗口

var response = confirm('Are you sure you want to clear the form?');
if (response){
   // clear the form
   console.log('clearing the form approved');
}

confirm窗口与alert类似,只是显示"确定""取消"按钮。它根据用户的选择返回bool结果。

alert窗口一样,它会停止程序/脚本执行,直到用户做出决定

相关文章: