开发者

Why is $(this).val() giving me the value from this first method in this second method?

开发者 https://www.devze.com 2023-03-12 21:23 出处:网络
The $(this).val() in the second method returns the same value that I get in the first method.I expected to get the first value of the fields with the secondGroup class.What am I doing wrong?

The $(this).val() in the second method returns the same value that I get in the first method. I expected to get the first value of the fields with the secondGroup class. What am I doing wrong?

$(document).ready(function(){

  jQuery.validator.addMethod("meth开发者_JAVA技巧od1", 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", 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."));


 $("#formName").validate({

 rules: {
   firstMethod1:{
       method1: ['.firstGroup']
   },
   secondMethod1:{
       method1: ['.firstGroup']
   },
   thirdMethod1:{
       method1: ['.firstGroup']
   },
   firstMethod2:{
       method2: ['.secondGroup']
   },
   secondMethod2:{
       method2: ['.secondGroup']
   },
   thirdMethod2:{
       method2: ['.secondGroup']
   }

   }
 });

});


You are using jQuery.each() instead of .each().

Use:

elems.each(function(){ 
    thisVal = $(this).val(); 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消