在 alertify 确认对话框上添加自定义按钮

add custom buttons on alertify confirm dialog box

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

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

    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