1

我对 jQuery 很陌生。

我编写了这段代码来选择子 TD 元素。

$(this)
    .children("div.tablescroll_wrapper")
    .children("table.tablescroll_body")
    .children("tbody")
    .children("tr.first")
    .children()

工作正常,但看起来很糟糕,有没有更好的方法来做到这一点?

对不起我的英语水平低,谢谢

4

3 回答 3

5

我不确定您的 html 结构,但是您可以通过以下方式实现您想要实现的目标,

$(this).find("div.tablescroll_wrapper tr.first").children();
于 2012-05-17T09:23:43.423 回答
0

您不必浏览整个树。只需为表设置一个 id 或直接选择 tr 即可:

   $(this).find('tr:first').children();

已经足够好了。否则,选择具有表 id 的表:

于 2012-05-17T09:24:17.797 回答
0
$('div.tablescroll_wrapper > table.tablescroll_body > tr.first', this).children();

或者

$('div.tablescroll_wrapper > table.tablescroll_body > tr.first > *', this);
于 2012-05-17T09:28:01.567 回答