2012-05-08 42 views
0

使我有jQuery的一些代码,见下图:jQuery UI的按钮不起作用后停用/ IFRAME从

$(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启用按钮时。

回答

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:​​

0

我已经清理你的代码了一下,做出像你描述它。

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

退房小提琴here

0

谢谢大家对你的答案。我解决了以下方式问题:

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'); 
});