我正在使用Alertify js 1.6.1在用户离开页面时显示对话框。除了Ok和Cancel之外,我还需要在alertify js确认对话框中添加一个额外的按钮“continue”。有没有办法添加自定义按钮功能?如果您有任何想法,请告诉我。感谢
答案 0 :(得分:5)
您可以自己构建或扩展现有的确认:
alertify.dialog('myConfirm', function() {
var settings;
return {
setup: function() {
var settings = alertify.confirm().settings;
for (var prop in settings)
this.settings[prop] = settings[prop];
var setup = alertify.confirm().setup();
setup.buttons.push({
text: '<u>C</u>ontinue',
key: 67 /*c*/ ,
scope: 'auxiliary',
});
return setup;
},
settings: {
oncontinue: null
},
callback: function(closeEvent) {
if (closeEvent.index == 2) {
if (typeof this.get('oncontinue') === 'function') {
returnValue = this.get('oncontinue').call(this, closeEvent);
if (typeof returnValue !== 'undefined') {
closeEvent.cancel = !returnValue;
}
}
} else {
alertify.confirm().callback.call(this, closeEvent);
}
}
};
}, false, 'confirm');
请参阅example