Disable button until required fields are valid
问题 I've searched for the answer to this problem but still can't get this to work: <script type="text/javascript"> $(document).ready(function (){ validate(); $('#contact_subject').change(validate); }); function validate(){ if ($('#contact_subject').val().length > 0 { $('button').prop('disabled', false); } else { $('button').prop('disabled', true); } } </script> I want to make sure #contact_subject has data or else disable the button. 回答1: Change the event.Try this: http://jsfiddle.net/e0t7qv56/1/