我正在尝试升级我的 JavaScriptconfirm()
使用的动作甜蜜警报 https://sweetalert.js.org/。目前我的代码是这样的:
<a href="/delete.php?id=100" onClick="return confirm('Are you sure ?');" >Delete</a>
这将等待用户确认,然后再导航到删除页面。我想使用 SweetAlert 中的这个示例来要求用户在删除之前确认:
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
}
else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
我尝试过的一切都失败了。当显示第一个警报时,在用户单击警报按钮之前,页面已继续删除该项目并刷新。如何让页面等待用户输入?
任何帮助将不胜感激。