Jquery 哪个最快?查找()或标准
我只是想知道,我现在已经开始在jQuery中缓存DOM对象了。例如,假设这是我的文档:Jquery 哪个最快?查找()或标准,jquery,Jquery,我只是想知道,我现在已经开始在jQuery中缓存DOM对象了。例如,假设这是我的文档: <div class="test"> <a href="#">Test</a> </div> 然而,现在我正在做这件事,我想知道选择缓存对象的子对象的最佳方法是什么 $('a', $test) // the standard method, only searching the cached object $test.find('a') // usin
<div class="test">
<a href="#">Test</a>
</div>
然而,现在我正在做这件事,我想知道选择缓存对象的子对象的最佳方法是什么
$('a', $test) // the standard method, only searching the cached object
$test.find('a') // using find() on the cached object
这两种方法一下子就浮现在我的脑海里,什么方法最快?最好的方法是什么
提前谢谢。它们完全一样
在内部,选择器上下文是通过.find()
方法实现的,因此$(“span”,this)
相当于$(this).find(“span”)
第一种方法使用内存中的第二种方法。好的,谢谢。我不知道为什么我被否决了,但是谢谢你的回答。可能是因为你也可以自己阅读文档。
$('a', $test) // the standard method, only searching the cached object
$test.find('a') // using find() on the cached object