jQuery disabled button with checkbox issue

后端 未结 1 1660
死守一世寂寞
死守一世寂寞 2021-01-23 09:59

I have the following code which enables a button when the checkbox is checked.

http://jsfiddle.net/ERfWz/1/

The following is a snippet from the code I have in my

相关标签:
1条回答
  • 2021-01-23 10:14

    You can also set disabled with true and false, so you can simplify it down to:

    $(function() {
      $('#agree').change(function() {
        $('#submit').attr('disabled', !this.checked);
      });
    });​
    

    Test it out here, note there was also some invalid markup going on resulting in some cross-browser inconsistencies, it should look something like this:

    <form>
      <table>
        <tr><td align="center"><input type="checkbox" name="agree" id="agree">I agree Terms and Conditions</td></tr>
        <tr><td align="center"><input type="submit" name="submit" id="submit" value="submit" disabled></td></tr>
      </table>
    </form>
    

    Also the .change() method's a bit better here, to ensure you have the correct state.

    0 讨论(0)
提交回复
热议问题