1

javascript 確認ボックスをSweetAlertでオーバーライドしようとしています。これについても調査しましたが、適切な解決策が見つかりません。

私は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 に答える