[英]Why alertify confirm cancel button not working?
我在我的 spring mvc 項目中使用alertify.confirm()
。
alertify.confirm(
"Press OK to Confirm",
function(){ console.log("ok") },
function(){ console.log("canceled") });
但是每當我按下OK
或CANCEL
按鈕時,它都會在控制台中打印“ok”。 為什么會這樣?
Alertify的confirm
有四個參數,不是三個: title: string, message: string, onOK: function, onCancel: function )
將您的代碼更改為:
alertify.confirm(
/*title: */ "Confirm low-effort stackoverflow posting"
/*message:*/ "Press OK to Confirm posting a question to stackoverflow without doing a quick 15-seconds google search",
/*ok: */ function(){ console.log("ok") },
/*cancel: */ function(){ console.log("canceled, good, the world is better for you having done your research first") }
);
我確實在他們的文檔頁面中看到了 3 個參數的重載,[但是 Alertify 的confirm.js][2]
將onok
參數重新用於oncancel
- 我認為這是一個錯誤:
main: function (_title, _message, _onok, _oncancel) {
var title, message, onok, oncancel;
switch (arguments.length) {
case 1:
message = _title;
break;
case 2:
message = _title;
onok = _message;
break;
case 3:
message = _title;
onok = _message;
oncancel = _onok;
break;
case 4:
title = _title;
message = _message;
onok = _onok;
oncancel = _oncancel;
break;
}
this.set('title', title);
this.set('message', message);
this.set('onok', onok);
this.set('oncancel', oncancel);
return this;
},
鑒於 AlertifyJS在六年內沒有顯着更新,我認為您應該考慮使用不同的對話框庫。 考慮使用原生 HTML5 <dialog>
代替。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.