【问题标题】:How to add and remove button dynamically from particular state in impromptu?如何即兴从特定状态动态添加和删除按钮?
【发布时间】:2015-06-24 01:45:36
【问题描述】:

我正在使用即兴提示,我想在特定条件下动态添加按钮。

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"

【问题讨论】:

  • 那么你的问题是什么?
  • 我想在特定条件下显示“NEWCONFIG”按钮。它不应该在 promt 上一直显示

标签: jquery impromptu impromptu-interface


【解决方案1】:

在初始化 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();
    }
},

就是这样..如果有任何问题,请告诉我!

【讨论】:

  • 任何时候.. 快乐编码.. :)
猜你喜欢
  • 1970-01-01
  • 2019-06-03
  • 1970-01-01
  • 2019-12-22
  • 2011-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-20
相关资源
最近更新 更多