Jquery 使用eq()根据索引获取所有tds
我有索引2-即第3列、0-第1列、1-第2列和2-第3列,使用下面的选择器,我只从正确的列中获得1个td,但是我想要索引2中的所有tds,我如何实现这一点Jquery 使用eq()根据索引获取所有tds,jquery,jquery-selectors,Jquery,Jquery Selectors,我有索引2-即第3列、0-第1列、1-第2列和2-第3列,使用下面的选择器,我只从正确的列中获得1个td,但是我想要索引2中的所有tds,我如何实现这一点 $($(selector).find("td").eq(currentCol)).each(function(i) { Console.log("Left-", currentCol,$(this).width() - diff); $(this).css("width", ($(this).width() + diff) + "p
$($(selector).find("td").eq(currentCol)).each(function(i) {
Console.log("Left-", currentCol,$(this).width() - diff);
$(this).css("width", ($(this).width() + diff) + "px");
});
Html:
不如改用CSS选择器呢?你应该做你想做的事:
$(selector).find("tr td:nth-of-type(3)")
不如改用CSS选择器呢?你应该做你想做的事:
$(selector).find("tr td:nth-of-type(3)")
您可以循环遍历每一行并获取列位置/索引的td:
$(selector).find('tr').each(function(){
var td = $(this).children('td').eq(2);
//do some other stuff with the td
});
其中2是列位置/索引
注意:通过阅读文档,使用.eq函数只会返回一个结果,因此现有代码只会影响一个元素。您可以循环每行并获取列位置/索引的td:
$(selector).find('tr').each(function(){
var td = $(this).children('td').eq(2);
//do some other stuff with the td
});
其中2是列位置/索引
注意:通过阅读文档,使用.eq函数只会返回一个结果,因此现有代码只会影响一个元素