jQuery的一个错误验证多个字段 [英] JQuery Validate multiple fields with one error
本文介绍了jQuery的一个错误验证多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何使用JQuery Validate插件针对3个字段显示一条错误消息.例如3个dob字段.默认情况下,如果所有3个字段均保留为空白,我将收到3条错误消息.我只想要一个链接到3个字段的错误.如果有任何空白,则会出现错误.
How would I use the JQuery Validate plugin to have one error message for say 3 fields. For example 3 dob fields. By default I will get 3 error messages if all 3 fields are left blank. I only want one error linked to 3 fields. If any are blank the error comes up.
推荐答案
类似于克里斯的
$("form").validate({
rules: {
DayOfBirth: { required: true },
MonthOfBirth: { required: true },
YearOfBirth: { required: true }
},
groups: {
DateofBirth: "DayOfBirth MonthOfBirth YearOfBirth"
},
errorPlacement: function(error, element) {
if (element.attr("name") == "DayOfBirth" || element.attr("name") == "MonthOfBirth" || element.attr("name") == "YearOfBirth")
error.insertAfter("#YearOfBirth");
else
error.insertAfter(element);
}
});
这篇关于jQuery的一个错误验证多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文