3

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

4

1 回答 1

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

例子

于 2016-03-15T20:10:50.423 回答