我alertify.confirm()
在我的 spring mvc 项目中使用。
alertify.confirm(
"Press OK to Confirm",
function(){ console.log("ok") },
function(){ console.log("canceled") });
但是每当我按下OK
或CANCEL
按钮时,它都会在控制台中打印“ok”。为什么会这样?
我alertify.confirm()
在我的 spring mvc 项目中使用。
alertify.confirm(
"Press OK to Confirm",
function(){ console.log("ok") },
function(){ console.log("canceled") });
但是每当我按下OK
或CANCEL
按钮时,它都会在控制台中打印“ok”。为什么会这样?
Alertifyconfirm
有四个参数,而不是三个: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>
。