我有一个非常简单的表单,其中包含几个字段和几个复选框。我需要的是当postto
复选框被选中时,它会在提交之前调用一个函数。
我怎么能做到这一点?
$("#form").validate({
debug: true,
errorContainer: $(".warning"),
rules: {
comment: {
maxlength: 25
},
'phone': {
number: true
}
},
submitHandler: function(form) {
form.submit();
}
});
<form id="form" method="post">
<div class="first"><textarea name="comment" id="comment" tabindex="1" placeholder="Write your fondest memory here *" required></textarea></div>
<div><label for="firstname">First Name *</label><input name="firstname" type="text" id="firstname" tabindex="2" required></div>
<div><label for="lastname">Last Name *</label><input name="lastname" type="text" id="lastname" tabindex="3" required></div>
<div><label for="email">Email Address *</label><input name="email" type="email" id="email" tabindex="4" required></div>
<div><label for="phone">Phone Number *</label><input name="phone" type="text" id="phone" tabindex="5" required></div>
<section>
<div class="postto"><input name="postto" type="checkbox" id="postto" value="1" tabindex="6"><label for="postto">Post to my wall</label></div>
<div class="newsletter"><input name="newsletter" type="checkbox" id="newsletter" value="1" tabindex="7"><label for="newsletter">I want to sign up to the Penguin newsletter</label></div>
<div class="submit-button"><input name="submitbutton" type="submit" value="enter" tabindex="8"></div>
<p class="warning">^ Please fill in the required fields with the correct information.</p>
</section>
</form>