以下哪个选择器具有更好的性能,如果不相同的话
$('#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
更多推荐
发布评论