cloest('td, th') 和 pushStack($cells); 不懂,请教

xiaotuzi 2020-05-08 11:29:10
(function($) {
$.fn.column = function() {
var $cells = $();
this.each(function() {
var $td = $(this).closest('td, th');
if ($td.length) {
var colNum = $td[0].cellIndex + 1;
var $columnCells = $td
.closest('table')
.find('td, th')
.filter(':nth-child(' + colNum + ')');
$cells = $cells.add($columnCells);
}
});
return this.pushStack($cells);
};
})(jQuery);
cloest('td, th') 中间有 td, th 是什么意思呢?我仅仅能够看见 cloest('td') 或者 closest('th')的用法,表示上溯一个父元素。两个一起放在参数里,是什么意思呢?

最后的 return this.pushStack($cells); 是什么意思呢? 直接用 return $cells;不可以吗?如果对DOM树有影响,return $cells;会造成怎样的影响呢?
谢谢老师
...全文
47 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧