jQuery to disable button not work

后端 未结 3 550
走了就别回头了
走了就别回头了 2021-01-03 23:00

I used to bind event to my button like :

$(\"input[name=add]\").live(\"click\",function(){...});

But I got another function to make them \"

相关标签:
3条回答
  • 2021-01-03 23:28

    You'll want to use the prop function instead of attr:

    $(this).prop("disabled", true);
    

    and

    $(this).prop("disabled", false);
    

    EDIT

    OP was using jQuery pre 1.6.1, which was why attr for disabled wasn't working quite right (for older IE). While prop is preferred for disabled, post 1.6.1 attr should (and does) work as well.

    0 讨论(0)
  • 2021-01-03 23:28

    Try $("input[type=submit]").removeAttr("disabled"); to enable the button.

    0 讨论(0)
  • 2021-01-03 23:31

    You can set the 'disabled' attribute to false by using:

    $("input[name='add']").attr("disabled","disabled");
    
    0 讨论(0)
提交回复
热议问题