jQuery 验证 - 如何在 errorPlacement 回调中分离错误?
jQuery Validation - how to separate errors within the errorPlacement callback?
errorPlacement: function (error, element) {
$('#div').append(error.html());
}
我想在调用此函数时在我的网页的 div 中附加一个错误列表。现在我只是调用 error.html() ,它给我在消息函数中列出的所有错误列表并连接在一起。
例如 div:
Title is requiredNumber of words must be between 50 and 65Picture is
Required
如果需要,我可以提供更多代码。
errorPlacement
是 option/function 用于将每个单独的错误放在每个单独的输入字段旁边。如果您想要错误列表,则不能使用此选项。
如果您想创建一个错误消息列表,那么您可以使用 the showErrors
option. Refer to the documentation 作为示例用法...
showErrors: function(errorMap, errorList) {
$("#summary").html("Your form contains "
+ this.numberOfInvalids()
+ " errors, see details below.");
this.defaultShowErrors();
}
通用演示:http://jsfiddle.net/0k0vL1b0/
如果您想抑制每个字段旁边的消息,只需注释掉 this.defaultShowErrors()
行并编写一些代码以从提供的 errorList
参数中提取消息。
errorPlacement: function (error, element) {
$('#div').append(error.html());
}
我想在调用此函数时在我的网页的 div 中附加一个错误列表。现在我只是调用 error.html() ,它给我在消息函数中列出的所有错误列表并连接在一起。
例如 div:
Title is requiredNumber of words must be between 50 and 65Picture is Required
如果需要,我可以提供更多代码。
errorPlacement
是 option/function 用于将每个单独的错误放在每个单独的输入字段旁边。如果您想要错误列表,则不能使用此选项。
如果您想创建一个错误消息列表,那么您可以使用 the showErrors
option. Refer to the documentation 作为示例用法...
showErrors: function(errorMap, errorList) {
$("#summary").html("Your form contains "
+ this.numberOfInvalids()
+ " errors, see details below.");
this.defaultShowErrors();
}
通用演示:http://jsfiddle.net/0k0vL1b0/
如果您想抑制每个字段旁边的消息,只需注释掉 this.defaultShowErrors()
行并编写一些代码以从提供的 errorList
参数中提取消息。