[英]Override javascript confirm box
我試圖用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
。
請建議我,我應該為覆蓋確認框做些什么。
由於自定義實現不是阻塞調用,因此需要像
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.