Hai*_*ood 4 javascript jquery jquery-selectors
目前我正在使用
$('table').children('tfoot').children('tr').children('td');
获得tfoot中唯一的td.
我不喜欢使用.children()3次,
有没有更好的办法?
var table = this;
$(table).children('tfoot').children('tr').children('td');
Run Code Online (Sandbox Code Playgroud)
因为这是一个jquery插件.
$('table > tfoot > tr > td')
Run Code Online (Sandbox Code Playgroud)
children()在直接的孩子中搜索,所以为了复制这个,我使用了直接后代的selector(>).
从您的更新,你可以做...
$(table).find(' > tfoot > tr > td')
Run Code Online (Sandbox Code Playgroud)
或者你可以替换table使用this.
我很高兴你在想孩子们.