我经常发现自己在操作表格时做这样的事情:-
$($('table tr').children()[2]).html();
当我想要将第三列中的单元格作为 jQuery 包装集时。使用 [n]
选择节点,然后传递给 $()
以获取 jQuery 包装集。
有没有更简洁、更易读的方法来做到这一点?
最佳答案
使用.eq()
方法
$('table tr').children().eq(2).html();
<小时/>
您也可以使用:eq
selector
$('table tr > :eq(2)').html();
关于jquery - 使用 jQuery 执行 $($(this).children()[1]).html()) 的更紧凑/可读的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10746730/