[英]Jquery Validation, how do I run custom code if there are errors
I want to check for validation on multiple fields in a form. 我想检查表单中多个字段的验证。 If there are any errors whatsoever I want to run some custom jQuery to hide and show various elements.
如果有任何错误,我想运行一些自定义jQuery来隐藏和显示各种元素。
I have the validation below, my question is how do I now check if there are errors to run my custom code? 我在下面进行验证,我的问题是,现在如何检查是否有错误运行我的自定义代码?
$("#signupForm").validate({
rules: {
firstname: "required",
lastname: "required",
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
},
email: {
required: true,
email: true
},
topic: {
required: "#newsletter:checked",
minlength: 2
},
agree: "required"
},
You can call the form()
method after the validate
: 您可以在
validate
之后调用form()
方法:
if($('form')
.validate(RULES)
.form()){
//put your code here
}
See the documentation for the Validator Object . 请参阅Validator对象的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.