这两个选择器有什么区别

这两个选择器有什么区别

本文介绍了这两个选择器有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(this).parents('table:first > tbody > tr')

还有

$(this).parents('table:first').children('tbody').children('tr')

推荐答案

不同之处在于,第一个选择器完全在parents调用之内,而第二个选择器则不在.

The difference is that the first selector is entirely within the parents call, whereas the second one isn't.

因此,第一个查找与table:first > tbody > tr匹配的所有this父母. (换句话说,第一个table中包含thistr)

Therefore, the first one looks for all parents of this which match table:first > tbody > tr. (In other words, a tr containing this that is in the first table)

第二个将找到与table:first匹配的this的父级,然后直接在该父级的tbody内找到所有tr. (换句话说,所有tr都直接位于父表内部)

The second one will find the parent of this which matches table:first, then find all of the trs directly within tbodys of that parent. (In other words, all of the trs directly inside the parent table)

这篇关于这两个选择器有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:41