我看过这里并尝试了所有可用的答案,但它仍然不适合我。如果未选中复选框,我正在尝试禁用提交按钮。这是我的jQuery:
var userTerms = $('input#agree');
if(userTerms.is(':checked')) {
$("#aggtxt").addClass("err");
$("#aggtxt").removeClass("error");
$("#aggtxt").text(" Agreed");
$("#bookit").attr('disabled', false);
}else{
$("#aggtxt").removeClass("err");
$("#aggtxt").addClass("error");
$("#aggtxt").text(" Please check terms and conditions box");
$("#bookit").attr('disabled', true);
}
if ($('#bookit').is(':disabled') == true) {
$("#booktxt").removeClass("err");
$("#booktxt").addClass("error");
$("#booktxt").text(" Before you can submit this form please check the errors in form marked in red.");
}else{
$("#booktxt").addClass("err");
$("#booktxt").removeClass("error");
$("#booktxt").text(" Your information looks good, continue to booking...");
}
});
和我的 HTML 表单的一部分:
<p><span id="aggtxt"></span><br /><input type="checkbox" name="agree" id="agree" /> I agree to <a href="http://travel.ian.com/index.jsp?pageName=userAgreement&locale=en_US&cid=379849" target="_blank">Terms and Conditions</a> and understand Cancellation Policy.<p>
<span id="booktxt"></span>
<input type="submit" name="bookit" value="" class="bookit" id="bookit" />