问题描述
无论您单击“ Confirm
”还是“ Cancel
”,它们均执行“ isConfirm
”功能,并且“ Cancel
”不会关闭警报它应该已经做到了。基本上,它似乎正在关闭并吞并在确认功能中触发的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 please!",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");
}
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert@1.1.3/dist/sweetalert.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert@1.1.3/dist/sweetalert.min.js"></script>
解决方法
@Tschallacka是的,它与 sweetalert 正常运行,但不适用于 sweetalert2
以下是适用于 sweetalert2 的正确语法的解决方案:
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 please!",closeOnConfirm: false,closeOnCancel: false
}).then(result => {
if (result.value) {
swal("Deleted!","Your imaginary file has been deleted.","success");
}
else {
swal("Cancelled","Your imaginary file is safe :)","error");
}
});
希望它将对未来的读者有所帮助!