1

我正在尝试使用SweetAlert覆盖 javascript 确认框。我也对此进行了研究,但找不到合适的解决方案。

我正在这样confirm使用

if (confirm('Do you want to remove this assessment') == true) {
   //something
}
else {
   //something
}

我正在使用它来覆盖

 window.confirm = function (data, title, okAction) {
                swal({
                    title: "", text: data, type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes", cancelButtonText: "No", closeOnConfirm: true, closeOnCancel: true
                }, function (isConfirm) {
                    if (isConfirm)
                    {
                        okAction();
                    }
                });
                // return proxied.apply(this, arguments);
            };

现在确认框已替换为 sweetalert。当用户单击Yes按钮OK action时,应调用确认框。但这不是电话

并且在上面的代码中发生了错误Uncaught TypeError: okAction is not a function

请建议我应该为覆盖确认框做些什么。

4

1 回答 1

1

由于自定义实现不是阻塞调用,因此您需要像这样调用它

confirm('Do you want to remove this assessment', function (result) {
    if (result) {
        //something
    } else {
        //something
    }
})


window.confirm = function (data, title, callback) {
    if (typeof title == 'function') {
        callback = title;
        title = '';
    }
    swal({
        title: title,
        text: data,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes",
        cancelButtonText: "No",
        closeOnConfirm: true,
        closeOnCancel: true
    }, function (isConfirm) {
        callback(isConfirm);
    });
    // return proxied.apply(this, arguments);
};
于 2015-05-26T05:21:41.953 回答