jQuery选择器DOM遍历方向与效率
多部分 jQuery
选择器的标准搜索方向是什么?
例如,
$('#myTable tr.selected');
第一次搜索#myTable
,然后tr.selected
搜索仅在该表内吗?
或者是第一次搜索页面上的所有 tr.selected ,第二次搜索检查每个父节点?
What is the standard direction of search for multipart jQuery
selectors?
e.g. the case
$('#myTable tr.selected');
Is the first search for #myTable
and then the tr.selected
search is only within that table?
Or is the first search for all tr.selected
on the page and the second search checking each ones parent nodes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该观看John Resig 关于该主题的演讲。他说,与您的预期相反,选择器引擎将搜索
tr.selected
,然后查看祖先是否与#myTable
匹配。You should watch this talk by John Resig on the subject. He says that, contrary to what you might expect, selector engines will search for
tr.selected
and then see if an ancestor matches#myTable
.首先,它查找 id 为
myTable
的元素然后查找带有selected
类的“tr”标签的后代First it looks for an element with the id of
myTable
and then finds descendants that are 'tr' tags with theselected
class