0

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 からボタンを有効にすると発生します。

4

3 に答える 3

0

私はあなたのコードを少し整理し、あなたが説明したように機能させました。

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

ここでフィドルをチェックしてください

于 2012-05-08T15:54:30.957 に答える
0

回答ありがとうございます。次の方法で問題を解決しました。

親.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');
});
于 2012-05-08T20:46:09.463 に答える
0

試す

$(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/

于 2012-05-08T15:22:51.330 に答える