我正在尝试升级我的 JavaScriptconfirm()
操作以使用SweetAlert。目前我的代码是这样的:
<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");
}
});
我尝试过的一切都失败了。当显示第一个警报时,页面已经继续并删除了该项目并在用户单击警报按钮之前刷新。如何让页面等待用户输入?
任何帮助将不胜感激。