微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

确认/取消SweetAlert都得到确认

如何解决确认/取消SweetAlert都得到确认

无论您单击“ 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");
        }
    });

希望它将对未来的读者有所帮助!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。