Jquery - table 遍历

Table遍历行:

  

$(document).ready(function() {  
        $("#table a").each(function (){  
        this.onclick = function(){  
            var thisObj = this.parentNode.parentNode;  
            var a = $(thisObj).children();  
            var arr = new Array();  
            var laber = $("#xiugai label");  
            for(var i=0;i<a.length;i++){  
                arr[arr.length] = a.eq(i).text();  
            }  
            for(var i=0;i<laber.length;i++){  
                laber.eq(i).text(arr[i]);  
            }  
              
            $("#table").hide();  
            $("#xiugai").show(2000)  
        }  
    });  
});  
  
function fanhui(){  
    $("#table").show(2000);  
    $("#xiugai").hide(2000);      
}  


Table 遍历列:

 

$("table tr td:eq(5)").each(){  //循环table的第五列
alert($(this).html());
} 

 

 $("#attachmentTemp").each(function () {
                var tr = this.childNodes;
                for (var i = 0; i < tr.length; i++) {
                    if (i % 2 != 0) {
                        tr[i].className = 'alter';
                    }
                    else {
                        tr[i].className = 'alterNo';
                    }
                }
   });


ar table = document.getElementById('tblOne'),
    rowLength = table.rows.length

for (var i = 0; i < rowLength; i += 1) {
    var row = table.rows[i],
        cellLength = row.cells.length    

    // your code goes here, looping over every row.
    // cells are accessed as easy    

    for (var y = 0; y < cellLength; y += 1) {
        var cell = row.cells[y]

        //do something with every cell here
    }
}


 
$('#tblOne > tbody  > tr').each(function() {...code...});


 $("#tab tr td:nth-child(1)").each
                    (
                        function()
                        {
                             alert($(this).text());
                        }
                    );


  $("table[id^=ctl] input[type=radio]").each(function(i) { 
               arr.push(this.checked); 
        });

$("table[id^=ctl] input[type=radio]") 或者   

           $("table[id^=ctl]").find("input[type=radio]"



先获得你拖动的那里列的tr然后jquery 里面有个相当好用的方法 :nth-child

              你自己可以去琢磨琢磨:nth-child 返回值:Array<Element(s)>概述匹配其父元素下的第N个子或奇偶元素':eq(index)' 只匹配一个元素,而这个将为每一个父元素匹配子元素。:nth-child从1开始的,而:eq()是从0算起的!可以使用:nth-child(even):nth-child(odd):nth-child(3n):nth-child(2):nth-child(3n+1):nth-child(3n+2)参数indexNumber要匹配元素的序号,从1开始示例描述:在每个 ul 查找第 2 个liHTML 代码:<ul> <li>John</li> <li>Karl</li> <li>Brandon</li></ul><ul> <li>Glen</li> <li>Tane</li> <li>Ralph</li></ul>jQuery 代码:$("ul li:nth-child(2)")结果:[ <li>Karl</li>, <li>Tane</li> ]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值