$(Parent Child)和$(Parent).find(Child)之间的区别(在jQuery中) [英] Difference between $(Parent Child) and $(Parent).find(Child) (in jQuery)

查看:83
本文介绍了$(Parent Child)和$(Parent).find(Child)之间的区别(在jQuery中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
jQuery单个选择器与.find()

Possible Duplicate:
jQuery single selector vs .find()

$(Parent Child)和$(Parent).find(Child)在jQuery中是否有区别?

Is there any difference between $(Parent Child) and $(Parent).find(Child) in jQuery?

您可能有多个孩子,例如:

You may have multiple children like:

$("div").find("span")将返回所有子范围.但是$("div span")不一样吗?

$("div").find("span") which will return all the children spans. But isn't it the same with $("div span")?

推荐答案

一个非常重要的区别是$重载有多种含义,因此与用户定义的字符串一起使用时易受攻击,而find则不是

One very important difference is that $ is overloaded with several meanings and as a consequence vulnerable when used with user-defined strings, while find is not.

E. g.

$('.items .'+location.hash.substr(1)) // very bad idea
$('.items').find('.'+location.hash.substr(1)) // this is OK

这篇关于$(Parent Child)和$(Parent).find(Child)之间的区别(在jQuery中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆