jQuery上下文选择器与.find() [英] jquery context selector vs .find()
本文介绍了jQuery上下文选择器与.find()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么更有效?
var container = $("#container");
// 1
var links1 = container.find("a");
// 2
var links2 = $("a", container);
我个人更喜欢$("a", container)
,因为它看起来更好,但是它们的性能有所不同吗?
I personally prefer $("a", container)
because it looks better, but are they different in performance?
推荐答案
将上下文选择器$("a", container)
转换为find. find()
会更快,但是在大多数情况下可以忽略不计.我会选择find()
,因为它的语法对我来说是相当正确的.此 帖子 具有性能比较,可帮助您确定哪个您会使用的一种.
The context selector $("a", container)
is converted to find. find()
will be faster but in most cases this could be ignored. I would go for find()
as its syntax is quite stright forward for me. This post has performance comparison that would help you deciding which one you would use.
这篇关于jQuery上下文选择器与.find()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文