开发者

jQuery-ui: enabling disabled button doesn't restore event

开发者 https://www.devze.com 2023-04-07 15:44 出处:网络
I have a problem: after enable button, it look like enabled but isn\'t clickable. (reloading page fix this problem, but i won\'t do it). Firstly, on (document).ready, i disable this button.

I have a problem: after enable button, it look like enabled but isn't clickable. (reloading page fix this problem, but i won't do it). Firstly, on (document).ready, i disable this button.

For enable i do:

$("#submit_order").attr('disabled', false).removeClass( 'ui-state-disabled' );

for disable:

$("#submit_order").attr('disabled', true).addClass( 'ui-state-disabled' ); 

HTML code:

<button开发者_如何学Go id="submit_order">Send an order</button> 

button jQuery code:

$( "#submit_order" )
    .button()
    .click(function() {
          $( "#dialog-form" ).dialog( "open" );
});

When i clicked this button after enabling, code above didn't invoke.


Yes, previous answers may work for you, but for me the events weren't firing when I "re-enabled" the button with .removeAttr("disabled") and using .removeClass("ui-state-disabled").

The official answer appears to be

$(".selector").button("option", "disabled", true);

to disable, and

$(".selector").button("option", "disabled", false);

to enable a jQueryUI button()

from http://jqueryui.com/demos/button/#option-disabled


When You are writing

$("#submit_order").attr(...)

it means that you use stanadard attributes.

You are inconsistent: once You are using mentioned above method, and another time you are writing:

$( "#submit_order" ).button().....

try this:

$("#submit_order").button().attr('disabled', false).removeClass( 'ui-state-disabled' );

$("#submit_order").button().attr('disabled', true).addClass( 'ui-state-disabled' );


As I remember jQueryUI extends jQuery library by providing different components where most of them have methods enable() and disable().

You may try alternative (IMHO more preferred) way:

$('#submit_order').button().enable();
   and
$('#submit_order').button().disable();

this will free Your mind from manual managing attributes - JQUI do this self. This is powerful, because you may create buttons using different underlying elements (so that enabling and disabling them will use different methods) ex. Standard button uses attribute disabled="disabled" (browser implementation - standard)

But button made from anchor doesn't support this at all.


To enable try like this:

$('#submit_order').removeAttr('disabled').removeClass('ui-state-disabled');

and to disable:

$('#submit_order').attr('disabled', 'disabled').addClass('ui-state-disabled'); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号