Jquery的集合方法EACH()

Jquery的集合方法EACH()
1、
$("input[name='r2']").each(function(){
    if($(this).val()=='lmf')
    {
        this.checked = true;
    }  
})

2、
$("input[name='r2']").each(function(){
    this.checked = this.value == "lmf";
})

3、
$("input[name='r2']").each(
    function(i,item){
        if(item.value=='lmf')
        {
            item.checked = true;
        }
    }
)

4、
$.each(list,function(i,item){

})
有时候function的参数不能省略:

         if(!StringUtils.IsNullOrEmpty(liveStatus))
         {
             lives = liveStatus.split(",");
             var len = lives.length;
             var i = 0;
             for(i=0;i<len;i++)
             {
                 $("input[name='ck_LiveStatus']").each(
                     function(k,item) {
                         if(item.value == lives[i])
                         {
                             item.checked = true;
                         }
                         //this.checked = this.value == lives[i];因为里面有i变量不可以用这一句话
                     }
                 );
             }
          } 

原文地址:https://www.cnblogs.com/lmfeng/p/2231570.html