jQuery validate校验不通过时,进行回调函数

/*** 校验规则 ***/
	$.validator.addMethod("refundTypeDesc", function(value, element) {
		var regExp =/^[a-zA-Z]\w+$/;
		return this.optional(element) || (regExp.test(value));
	}, $.validator.format("字母数字下划线"));
	/*** 校验规则 ***/
	$.validator.addMethod("refundRate", function(value, element) {
		var regExp = /^\d(\.\d*){0,1}$|^[1-9]\d(\.\d*){0,1}$|^100(\.0+){0,1}$/;
		return this.optional(element) || (regExp.test(value));
	}, $.validator.format("输入范围为(0到100)")); 
	 
	$("#form-submit").click(function(){
		$("#form-submit").addClass("disabled");
	});
	
	 /*** 数据提交 ***/
	$("#form-refundConfig-save").validate({
		rules:{
			refundTypeDesc:{
				required:true,
				refundTypeDesc:true
			},
			refundRate:{
				required:true,
				refundRate:true
			},
			memo:"required"
		},
		debug:true,
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				success: function(result){
					$("#form-submit").removeClass("disabled");
					if(result.code == "0"){
						layer.msg(result.msg,{icon: 1,time:800},function(){
							var index = parent.layer.getFrameIndex(window.name);
							parent.reloadDatatable();
							parent.layer.close(index);
						});
					}else{
						layer.msg(result.msg,{icon:0});
					}
					$("#form-submit").removeClass("disabled"); 
				}
			});
		},
		 invalidHandler: function(form, validator) {  //不通过回调 
			        $("#form-submit").removeClass("disabled");
			                   } 
	});
}); 

invalidHandler:当指定校验的数据,不通过时,就触发invalidHandler事件。

你可能感兴趣的:(JS)