如何为 addClassRules
中添加的 require_from_group
添加组:{ }
。
$.validator.addClassRules("group_input", {
require_from_group: [1,".group_input"]
});
由于我不想在规则中给出名称,因为名称是动态生成的,因此我使用类进行了验证。我如何添加组,因为我收到每个文本字段的错误消息。
提前致谢。
最佳答案
您不能将 groups
选项放入 .addClassRules()
方法中。
groups
选项只能放在 .validate()
方法中。您必须通过字段的名称
属性引用这些字段。
$('#myform').validate({
// other options,
groups: {
myGroup: "field1name field2name field3"
}
});
但是,如果您有大量字段,或者在您的情况下,name
是动态生成的,您可以构建 .validate() 外部的名称列表
并简单地使用变量代替列表。
var names = ""; // create empty string
$('.group_input').each(function() { // grab each input starting w/ the class
names += $(this).attr('name') + " "; // append each name + single space to string
});
names = $.trim(names); // remove the empty space from the end
$('#myform').validate({
// other options,
groups: {
myGroup: names // reference the string
}
});
关于javascript - 在 addClassRules 中添加组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28272564/