问题描述
|
第二种方法中的$(this).val()返回与第一种方法相同的值。我希望通过secondGroup类获得字段的第一个值。我究竟做错了什么?
$(document).ready(function(){
jQuery.validator.addMethod(\"method1\",function(value,element,options) {
.....some code here....
var elems = $(element).parents(\'form\').find(options[0]);
jQuery.each(elems,function(){
thisVal = $(this).val();
});
.....some code here......
},jQuery.format(\"some message.\"));
jQuery.validator.addMethod(\"method2\",jQuery.format(\"some message.\"));
$(\"#formName\").validate({
rules: {
firstMethod1:{
method1: [\'.firstGroup\']
},secondMethod1:{
method1: [\'.firstGroup\']
},thirdMethod1:{
method1: [\'.firstGroup\']
},firstMethod2:{
method2: [\'.secondGroup\']
},secondMethod2:{
method2: [\'.secondGroup\']
},thirdMethod2:{
method2: [\'.secondGroup\']
}
}
});
});
解决方法
您使用的是
jQuery.each()
而不是.each()
。
采用:
elems.each(function(){
thisVal = $(this).val();
});