[英]Override javascript confirm box
I am trying to override javascript confirm box with SweetAlert . 我试图用SweetAlert覆盖javascript确认框。 I have researched also about this but I can't found proper solution.
我也对此进行了研究,但找不到合适的解决方案。
I am using confirm
like this 我正在使用像这样的
confirm
if (confirm('Do you want to remove this assessment') == true) {
//something
}
else {
//something
}
And I am using this for overriding 我正在使用它来覆盖
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);
};
Now confirm box is replaced with sweetalert. 现在,请确认框已替换为sweetalert。 When user click on
Yes
button then OK action
of confirm box should be called. 当用户单击“
Yes
按钮时,应调用确认框的“ OK action
。 But this isn't calling 但这不是
And In above code an error occurred Uncaught TypeError: okAction is not a function
. 并且在上面的代码中发生了错误
Uncaught TypeError: okAction is not a function
。
Please suggest me I should I do for override confirm box. 请建议我,我应该为覆盖确认框做些什么。
Since the custom implementation is not a blocking call, you need to call it like 由于自定义实现不是阻塞调用,因此需要像
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);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.