gpt4 book ai didi

javascript - $ ("body") 使用 Sizzle Engine 吗?

转载 作者:搜寻专家 更新时间:2023-11-01 04:47:51 25 4
gpt4 key购买 nike

我知道 $("#id") 更快,因为它映射到 native javascript 方法。 $("body")也是这样吗?

最佳答案

不,它不使用 Sizzle,$("body") 有一个特殊的快捷方式到位,you can see the code here :

    // The body element only exists once, optimize finding it
if ( selector === "body" && !context && document.body ) {
this.context = document;
this[0] = document.body;
this.selector = "body";
this.length = 1;
return this;
}

请注意,这与 $(document.body)完全相同,作为 $("body") 的结果上下文是document ,其中 $(document.body) (与任何其他 DOM 节点一样)有其自身的上下文。

关于javascript - $ ("body") 使用 Sizzle Engine 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4402597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com