【问题标题】:Jquery loop through all the rows in a table without first rowJquery循环遍历表中没有第一行的所有行
【发布时间】:2013-10-04 10:02:24
【问题描述】:
我需要遍历特定表的所有行,我已经完成了如下。在某一时刻,我需要删除匹配的表格行。我不知道如何跳过第一行并遍历所有其他行。我下面的代码正在遍历所有 tr。
$('#tbl_dynamic_call_dates > tbody > tr').each(
function() {
console.log($(this).find(\'td:first\').text());
if($.inArray($(this).find(\'td:first\').text(),array) == -1){
$(this).remove();
}
【问题讨论】:
标签:
javascript
jquery
html
html-table
【解决方案1】:
$('#tbl_dynamic_call_dates > tbody > tr').not(":first"). [....]
得到一切,但第一个
$('#tbl_dynamic_call_dates > tbody > tr:first'). [...]
或
$('#tbl_dynamic_call_dates > tbody > tr').first(). [...]
只获得第一个
【解决方案2】:
把你的选择器改成这个...
$('#tbl_dynamic_call_dates > tbody > tr:not(:first)')
【解决方案3】:
您可以使用:gt() Selector 来执行此操作,例如:
$('#tbl_dynamic_call_dates > tbody > tr:gt(0)').each(function() {...});
【解决方案4】:
$('#tbl_dynamic_call_dates > tbody > tr:gt(0)').each(/*...*/);
或者:
$('#tbl_dynamic_call_dates > tbody > tr').first().siblings().each(/*...*/);