确认/取消 SweetAlert 都得到确认
Confirm / Cancel SweetAlert are getting both confirmed
无论你点击“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");
}
});
希望对以后的读者有所帮助!
无论你点击“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");
}
});
希望对以后的读者有所帮助!