我对 jQuery 很陌生。
我编写了这段代码来选择子 TD 元素。
$(this)
.children("div.tablescroll_wrapper")
.children("table.tablescroll_body")
.children("tbody")
.children("tr.first")
.children()
它工作正常,但看起来很糟糕,有没有更好的方法来做到这一点?
对不起我的英语水平低,谢谢
我对 jQuery 很陌生。
我编写了这段代码来选择子 TD 元素。
$(this)
.children("div.tablescroll_wrapper")
.children("table.tablescroll_body")
.children("tbody")
.children("tr.first")
.children()
它工作正常,但看起来很糟糕,有没有更好的方法来做到这一点?
对不起我的英语水平低,谢谢
我不确定您的 html 结构,但是您可以通过以下方式实现您想要实现的目标,
$(this).find("div.tablescroll_wrapper tr.first").children();
您不必浏览整个树。只需为表设置一个 id 或直接选择 tr 即可:
$(this).find('tr:first').children();
已经足够好了。否则,选择具有表 id 的表:
$('div.tablescroll_wrapper > table.tablescroll_body > tr.first', this).children();
或者
$('div.tablescroll_wrapper > table.tablescroll_body > tr.first > *', this);