//解决validator验证插件多个name相同只验证第一的问题
//解决validator验证插件多个name相同只验证第一的问题
var validatorName = function () {
if ($.validator) {
$.validator.prototype.elements = function () {
var validator = this,
rulesCache = {};
// select all valid inputs inside the form (no submit or reset buttons)
return $(this.currentForm)
.find("input, select, textarea")
.not(":submit, :reset, :image, [disabled]")
.not(this.settings.ignore)
.filter(function () {
if (!this.name && validator.settings.debug && window.console) {
console.error("%o has no name assigned", this);
}
//注释这行代码
// select only the first element for each name, and only those with rules specified
//if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
// return false;
//}
rulesCache[this.name] = true;
return true;
});
}
}
}
在JS初始化的时候加载这段代码var validator= $(".checkInVat").validate({
rules: {
checkInRul :'required
},
messages: {
checkInRul:"Name不能为空",
},
errorClass: "error",
success: 'valid',
unhighlight: function (element, errorClass, validClass) { //验证通过
$(element).tooltip('destroy').removeClass(errorClass);
},
errorPlacement: function (label, element) {
// $(element).poshytip('destroy'); /*必需*/
$(element).attr('title', $(label).text()).tooltip('show');
}
});
$().on('click',function(){
try {
if ($(".checkInVat").valid()) {
//return false;
执行验证通过的代码
}
}catch (e) { }
})