2015-04-17 64 views
0

我使用即興提示,我想在特定條件下動態添加按鈕。如何在即興時從特定狀態動態地添加和刪除按鈕?

state0: { 
    html: 'Do you want to apply changes?', 
    buttons: { YES: 1, NO: 0 }, 
    focus: 1, 
    submit: function(e, v, m, f) { 
     if (v == 1) { 
      e.preventDefault(); 
      $.prompt.goToState('state1'); 
      return false; 
     } 
     $.prompt.close(); 
    } 
}, 

在該狀態下需要使用特定條件3個按鈕:
"NEWCONFIG", "YES", "NO";和其他條件,我需要2個按鈕:"YES", "NO"

+0

那麼你的問題是什麼? – phts

+0

我想在特定條件下顯示「NEWCONFIG」按鈕。它不應該顯示所有的時間promt –

回答

0

初始化之前定義按鈕變量您impromptu如下

var buttons={}; 
if(condition1) 
{ 
    buttons = { YES: 1, NO: 0 }; 
} 
else 
{ 
    buttons ={ NEWCONFIG:1, YES:1, NO:0}; 
} 

然後初始化impromptu

state0: { 
    html: 'Do you want to apply changes?', 
    buttons: buttons, 
    focus: 1, 
    submit: function(e, v, m, f) { 
     if (v == 1) { 
      e.preventDefault(); 
      $.prompt.goToState('state1'); 
      return false; 
     } 
     $.prompt.close(); 
    } 
}, 

就是這樣。讓我知道如果任何問題!!

+0

謝謝。它的作品:) –

+0

任何時候..快樂編碼.. :) –