jQuery选择如何在场景背后工作?(How does jQuery selection work behind the scene?)

系统教程 行业动态 更新时间:2024-06-14 16:57:17
jQuery选择如何在场景背后工作?(How does jQuery selection work behind the scene?)

以下哪个选择器具有更好的性能,如果不相同的话

$('#location_form input#id_name') $('#id_name')

我常常在脑海里出现像上面这样的问题。 我无法回答它们,因为我缺乏关于场景背后的选择工作的知识。

我的问:

对上述问题的回答/意见 解释jQuery选择如何在场景后工作的参考 在选择时,所有javascript框架的工作方式与jQuery相同吗?

谢谢你们。

Which one of the following selectors has better performance, if not the same

$('#location_form input#id_name') $('#id_name')

I often have questions like the above pop up in my mind. I can't really answer them because I lack the knowledge on how selection work behind the scene.

My asks:

answer/opinions to the question above references that explain how jQuery selection work behind the scene do all javascript frameworks work in the same way as jQuery when it comes to selection?

Thanks a bunch.

最满意答案

使用选择器,后者更快,因为jQuery确定您只想按ID选择并返回document.getElementByID : https : //github.com/jquery/jquery/blob/master/src/core.js#L145-165

以下是完整的源代码: https : //github.com/jquery/jquery/blob/master/src/core.js#L78-188

With your selectors, the latter is faster, as jQuery determines you only want to select by ID and returns document.getElementByID: https://github.com/jquery/jquery/blob/master/src/core.js#L145-165

Here is the full source code: https://github.com/jquery/jquery/blob/master/src/core.js#L78-188

更多推荐

本文发布于:2023-04-12 20:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/67d4c8a1c95c2fd8ebc58b97c692ae75.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:场景   工作   jQuery   scene   work

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!