cloest('td, th') 和 pushStack($cells); 不懂,请教
(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;会造成怎样的影响呢?
谢谢老师