how to disable submit button with jquery

前端 未结 6 2152
慢半拍i
慢半拍i 2020-12-09 15:11

I have a simple form to check the value of post code entered by the user against a variable,

I\'m trying to disable the submit button and do the check and give alert

6条回答
  •  半阙折子戏
    2020-12-09 15:24

    The W3C recommends to set that attribute to disabled="disabled", so:

    $('#submit_postcode').attr('disabled', 'disabled');
    

    Re-enabling can be done by removing the attribute:

    $('#submit_postcode').removeAttr('disabled');
    

    Setting the attribute to any value causes it to be disabled, even .attr('disabled', 'false'), so it has to be removed.

提交回复
热议问题