2016-03-15 77 views
2

我使用Alertify js 1.6.1在用户离开页面时显示对话框。除了Ok和Cancel,我还需要在alertify js confirm对话框中添加一个额外的按钮“继续”。有没有添加自定义按钮功能的方法?让我知道你是否有任何想法。由于在alertify确认对话框中添加自定义按钮

回答

2

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

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

+0

非常感谢这种反应,其实我早先曾试图延长确认对话框中alertify js的本身和自定义按钮显示正确。然而,我发现的一个问题是:当我点击继续,对话框不会关闭,如果我点击第二次继续,那么只有框被关闭。我尝试了alertify.closeall(),alertify.confirm.close()回调继续功能,但没有奏效。 – user596502

+0

我在我提供的示例中看不到这样的问题! –

+0

是的,这有点奇怪,我试着用你的例子,它完美的作品。但不是警告,我必须在继续函数的回调中进行一些处理。然后箱子不关闭。 'oncontinue':function(){// alertify.warning('continue'); \t \t location.hash ='#'+'id:'+ someResourceId; //有效但对话框不关闭 \t}, – user596502

相关问题