用jQuery做$($(this).children()[1]).html())的更紧凑/可读的方法

rgv*_*ley 5 jquery

我经常发现自己在操纵表时会做这样的事情: -

$($('table tr').children()[2]).html();
Run Code Online (Sandbox Code Playgroud)

当我希望第3列中的单元格作为jQuery包装集时.选择节点[n]然后传递给$()jQuery包装集.

是否有更简洁,更可读的方式来做到这一点?

Gab*_*oli 7

使用该.eq()方法

$('table tr').children().eq(2).html();
Run Code Online (Sandbox Code Playgroud)

你也可以使用:eq选择器

$('table tr > :eq(2)').html();
Run Code Online (Sandbox Code Playgroud)