附加到jquery验证和jquery.validate.unobtrusive中的showError函数
我使用的是第三方工具附加到jquery验证和jquery.validate.unobtrusive中的showError函数,jquery,jquery-validate,Jquery,Jquery Validate,我使用的是第三方工具 jquery.validate.min.js jquery.validate.unobtrusive.min.js 当我输入下面显示消息框的内容时。工具validatiion上的自定义验证失败。我想它也会使用“淋浴”。我理解,如果没有完整的代码库,这是一个很难回答的问题。我的问题是 淋浴错误后是否发生事件。或者有没有一种方法可以扩展到这个函数而不是重写它 $.validator.setDefaults({ showErrors: function (errorMa
- jquery.validate.min.js
- jquery.validate.unobtrusive.min.js
淋浴错误后是否发生事件
。或者有没有一种方法可以扩展到这个函数而不是重写它
$.validator.setDefaults({
showErrors: function (errorMap, errorList) {
$(".messagebox").show();
}
});
淋浴错误后是否发生事件
请参阅所有回调函数的文档:
或者有没有一种方法可以扩展到这个函数而不是重写
它
不可以。使用自定义回调函数(override)是实现这一点的典型方法
看;它检查您是否声明了自定义回调函数,然后使用您的函数而不是默认函数
// http://docs.jquery.com/Plugins/Validation/Validator/showErrors
showErrors: function( errors ) {
if ( errors ) {
// add items to error list and map
$.extend( this.errorMap, errors );
this.errorList = [];
for ( var name in errors ) {
this.errorList.push({
message: errors[name],
element: this.findByName(name)[0]
});
}
// remove items from success list
this.successList = $.grep( this.successList, function( element ) {
return !(element.name in errors);
});
}
if ( this.settings.showErrors ) {
this.settings.showErrors.call( this, this.errorMap, this.errorList );
} else {
this.defaultShowErrors();
}
}
defaultShowErrors: function() {
var i, elements;
for ( i = 0; this.errorList[i]; i++ ) {
var error = this.errorList[i];
if ( this.settings.highlight ) {
this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
}
this.showLabel( error.element, error.message );
}
if ( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers );
}
if ( this.settings.success ) {
for ( i = 0; this.successList[i]; i++ ) {
this.showLabel( this.successList[i] );
}
}
if ( this.settings.unhighlight ) {
for ( i = 0, elements = this.validElements(); elements[i]; i++ ) {
this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
}
}
this.toHide = this.toHide.not( this.toShow );
this.hideErrors();
this.addWrapper( this.toShow ).show();
}
您是否试图保留默认错误显示并添加自己的错误显示?如果是这样,只需添加
this.defaultShowErrors()代码>到您的自定义处理程序
$.validator.setDefaults({
showErrors: function (errorMap, errorList) {
$(".messagebox").show();
this.defaultShowErrors();
}
});
请参阅: