我有一个表单,在用户单击提交后检查有效字段。它看起来像这样:
<form class="form-horizontal" method="post" action="#" name="basic_validate" id="basic_validate" />
<div class="control-group">
<label class="control-label">Email Recipients</label>
<div class="controls">
<input type="text" name="emailreceipients" id="emailreceipients" />
</div>
</div>
<div class="form-actions">
<input type=submit value="Send" id="sendbtn" class="btn btn-primary" />
</div>
</form>
如果看到错误,则会将名为“error”的类添加到字段中。
删除所有错误后如何捕获表单提交(例如用户输入所有数据)
这是表单提交后得到的验证调用:
// Form Validation
$("#basic_validate").validate({
rules:{
required:{
required:true
},
emailreceipients:{
required:false
}
},
errorClass: "help-inline",
errorElement: "span",
highlight:function(element, errorClass, validClass) {
$(element).parents('.control-group').addClass('error');
},
unhighlight: function(element, errorClass, validClass) {
$(element).parents('.control-group').removeClass('error');
$(element).parents('.control-group').addClass('success');
}
});
我试过这样的事情:
$("#sendbtn").click(function (e) {
e.preventDefault();
if ($("#basic_validate").children('.control-group').hasClass('error')) {
alert("Error Seen");
}
else {
// Process Form
}
});
知道我怎么能做到这一点吗?