TG.WXCRM.V4/WEB/Scripts/jQuery.validator.noinput.js

30 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//扩展的方法名与NoInputAttribute保持一致且是小写
//value是指前端输入的值
//element是指html元素
//parm是指输入的参数即rule.ValidationParameters["input"]键input对应的值通过NoInputAttribute的构造函数注入的
$.validator.addMethod("noinput", function (value, element, param) {
if (value == false) { //如果value没有输入这里就放行
return true;
}
if (param.indexOf("[" + value + "]") != -1) { //如果前端输入的值value包含自定义验证特性NoInputAttribute的属性Input值就不放行
return false;
} else {
return true;
}
});
//第一个参数就是jquery验证扩展方法名
//第二个参数就是rule.ValidationParameters["input"]的键
$.validator.unobtrusive.adapters.addSingleVal("noinput", "input");
//两个时间比较,结束时间不能大于开始时间
$.validator.addMethod("notlessthan", function (value, element, params) {
if (!this.optional(element)) {
var otherProp = $('#' + params)
var stime = otherProp.val();
if (stime !== "" && value !== "") {
return (new Date(stime) < new Date(value))
}
}
return true;
});
$.validator.unobtrusive.adapters.addSingleVal("notlessthan", "otherproperty");