3

AlertifyJS 有一个放置辅助按钮的地方。

当我的辅助按钮被点击时,我希望发生两件事

  1. 对话框不应关闭
  2. 应该运行一些功能

我该怎么做这两件事?

我可以通过将通知作为第三个参数传递来显示通知,但对话框消失了。此外,如果我有多个辅助按钮和每个不同的功能,这将不起作用。

下面是我的 javascript,这里是一个 JSFiddle



    // Run this function when the auxiliary button is clicked
    // And do not close the dialog
    var helpInfo = function () {
        alertify.notify("help help help");
    };

    var custom = function () {
        if (!alertify.helper) {
            alertify.dialog('helper', function factory() {
                return {
                    setup: function () {
                        return {
                            buttons: [{
                                text: 'Help',
                                scope: 'auxiliary'
                            }],
                            options: {
                                modal: false
                            }
                        };
                    }
                };
            }, false, 'alert');
        }
        alertify.helper('Do you need help?', "hello world", helpInfo);
    };

    custom();

4

2 回答 2

1

AlertifyJS 回调将被传递一个特殊的closeEvent对象。要保持对话框打开,您的回调应将 cancel 属性设置为truereturn false

var helpInfo = function (closeEvent) {    
   alertify.notify("help help help");    
   closeEvent.cancel = true;
  //or
  //return false;
};

请参阅更新的小提琴

于 2015-03-06T18:22:09.947 回答
0

向函数添加一个附加参数,helpInfo以便您可以访问与事件一起传递的 Event 对象。现在您可以阻止它的默认操作(这将关闭对话框)。

var helpInfo = function (e) {
    alertify.notify("help help help");
    e.preventDefault();
};
于 2015-03-06T17:52:47.980 回答