在alertify确认对话框中添加自定义按钮 [英] add custom buttons on alertify confirm dialog box

查看:291
本文介绍了在alertify确认对话框中添加自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户离开页面时,我正在使用Alertify js 1.6.1显示对话框。除了确定和取消,我需要在alertify js确认对话框中添加一个额外的按钮继续。有没有办法添加自定义按钮功能?让我知道,如果你有任何想法。谢谢

I am using Alertify js 1.6.1 to show dialog box when user leaves a page. Apart from Ok and Cancel, I need to add one extra button "continue" in alertify js confirm dialog box. Is there a way to add custom button functionality? Let me know if you have any ideas on it. Thanks

推荐答案

您可以建立自己的或扩展现有的确认:

You can build your own or extend the existing confirm:

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');

请参阅示例

这篇关于在alertify确认对话框中添加自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆