Jquery.Form和jquery.validate 的使用

时间:2022-12-04 14:01:22

var form=$('#xxxForm');
var error=$('.alert-danger',form);
form.validate({
errorElement:'span',
errorClass:'help-block help-block-error',
focusInvalid:true,

messages:{
seatNo:{remote:"编号已经存在"}
},
rules:{
<#if action?? && action == 'create'>
seatNo:{
minlength:0,
maxlength:4,
required:true,
number:true,
remote:'${rc.contextPath}/xxxx'
},
</#if>
userName:{
required:true
}
},
messages: {
seatNo: { required: "不能为空", maxlength: jQuery.format("不能超过{0}个字符") ,number:"仅输入4位数字"},

},

invalidHandler:function(event,validator){
error.show();
Metronic.scrollTo(error,-200);
},
highlight:function(element){
$(element).closest('.form-group').addClass('has-error');
},
unhighlight:function(element){
$(element).closest('.form-group').removeClass('has-error');
},
success:function(label){
label.closest('.form-group').removeClass('has-error');
}
});


好文章这里写链接内容