为什么.find()比选择器更有效? [英] Why is .find() more effective than a selector?
本文介绍了为什么.find()比选择器更有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
webstorm(intellij)说
webstorm (intellij) says
$('#cards').find('.box .row')
比
$('#cards .box .row')
但是..为什么呢?我本以为这实际上是另一种方式
But.. why? I would had thought it would be other way actually
推荐答案
根据快速的jsPerf测试,实际上,它无需使用.find()
方法就可以更快.
According to a quick jsPerf test, it's actually quicker without using the .find()
method.
完全有可能结果因浏览器而异,但是似乎单个查询的速度明显要快得多.
It's entirely possible that the results may differ depending on your browser, but it seems like a single query is significantly faster.
结果:
// Fastest
// 112,996 operations
var text = $('#cards .box .row').text();
// 39% slower
// 69,350
var text = $('#cards').find('.box .row').text();
这篇关于为什么.find()比选择器更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文