jQuerydom遍历嵌套表格
jQuery dom traversal nested tables
我正在尝试从另一行中映射 table 行的数据 table 但我不确定如何到达那里。
我试过类似的东西:
$('.order_info .active').closest('tr').prev('tr').children('td').map(function(){
return $(this).text();
}).get();
$(this).find('.order_info .active').closest('tr').prev('tr').children('td').map(function(){
return $(this).text();
}).get();
但运气不好。
这就是 DOM 的样子以及我需要去的地方。
您可以通过 .parent().closest("tr")
找到包含该行所在的 table 的行(需要 .parent
,否则它会匹配您所在的行)。然后你通过 .prev()
.
得到前一个
如果您的出发点不是实际的 tr
,而是 内部的东西,那么 .closest("tr").parent().closest("tr").prev()
。例如,如果您想处理对该行中单元格的点击:
$(this).closest("tr").parent().closest("tr").prev();
如果上一行不是您想要的,您可以通过 .prevAll(".even").first()
.
扫描 .event
链接:
我正在尝试从另一行中映射 table 行的数据 table 但我不确定如何到达那里。
我试过类似的东西:
$('.order_info .active').closest('tr').prev('tr').children('td').map(function(){
return $(this).text();
}).get();
$(this).find('.order_info .active').closest('tr').prev('tr').children('td').map(function(){
return $(this).text();
}).get();
但运气不好。
这就是 DOM 的样子以及我需要去的地方。
您可以通过 .parent().closest("tr")
找到包含该行所在的 table 的行(需要 .parent
,否则它会匹配您所在的行)。然后你通过 .prev()
.
如果您的出发点不是实际的 tr
,而是 内部的东西,那么 .closest("tr").parent().closest("tr").prev()
。例如,如果您想处理对该行中单元格的点击:
$(this).closest("tr").parent().closest("tr").prev();
如果上一行不是您想要的,您可以通过 .prevAll(".even").first()
.
.event
链接: