jQuery disabled button with checkbox issue

后端 未结 1 1659
死守一世寂寞
死守一世寂寞 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:

    I agree Terms and Conditions

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

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