我正在尝试使用 jQuery ajaxForm 插件中的“beforeSubmit”选项来验证数据,但是即使有无效的表单字段,表单也会提交。我哪里出错了?谢谢,
$(document).ready(function() {
function validator(){
$("#commentForm").validate();
}
$('#commentForm').ajaxForm({
dataType: 'json',
url: "http://highlandfamilyeyecare.com/contactengine.php",
beforeSubmit: validator,
success: function(data) {
$('ul.form').fadeOut("slow");
$('ul.form').html(data.formula).slideDown('slow');}
});
});
和html:
<ul class="form">
<li>
<form method="post" action="form.php" id="commentForm">
<label class="white">Your Name</label>
<input class="text-input required" type="text" name="name" /></li>
<li>
<label class="white">Email</label>
<input class="text-input required email" type="text" name="email"/></li>
<li>
<li><input type='submit' value="Submit" />
</form></li>
</ul>