【问题标题】:jQuery UI Button doesn't work after disabled/enabled from iframe从 iframe 禁用/启用后,jQuery UI 按钮不起作用
【发布时间】:2012-05-08 15:16:36
【问题描述】:

我有一些 jQuery 代码,见下文:

$(function(){
    $('button#submit').button({disabled:true});
    $('button#submit').click(function(){
        console.log('It works!');
    });
    $('a#button-enable').click(function(){
        $('button#submit').button({disabled:false});
    });
});

如果 ID 为 button-enable 的链接未被点击,则必须禁用该按钮。之后必须启用该按钮,如果我单击它,则必须在控制台中输出文本It works!。为什么没有发生?

当我从 iframe 启用按钮时会发生这种情况。

【问题讨论】:

    标签: jquery jquery-ui button


    【解决方案1】:

    试试

    $(function(){
        $('button#submit').button("option", "disabled", true );
        $('a#button-enable').click(function(){
            $('button#submit').button("option", "disabled", false);
            $('button#submit').click(function(){
                alert('It works!');
            });
        });
    });
    

    这是来自http://jqueryui.com/demos/button/#option-disabled

    这是一个 jsfiddle:http://jsfiddle.net/tmx8t/

    【讨论】:

      【解决方案2】:

      我已经稍微清理了你的代码,让它像你描述的那样工作。

      $(function() {
          var button = $('#submit').button({
              disabled: true
          }).click(function() {
              alert('It Works');
          });
          $('#button-enable').click(function() {
              button.button('enable');
          });
      });​
      

      看看小提琴here

      【讨论】:

        【解决方案3】:

        谢谢大家的回答。我通过以下方式解决了这个问题:

        parent.html

        $(function{
            $('button, input[type="submit"]').button();
            $('button#submit').button('disable');
            $(document).bind('enableButton',function(){
                $('button#submit').button('enable');
            });
            $('button#submit').click(function(){
                //...
            });
        });
        

        iframe.html

        $(function(){
            //...
            parent.$(parent.document).trigger('enableButton');
        });
        

        【讨论】:

          猜你喜欢
          • 2023-03-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-01
          • 2021-06-06
          • 2017-08-28
          • 1970-01-01
          相关资源
          最近更新 更多