确认/取消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");
        }
    });

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...