$(父子)和$(父).find(子)之间的区别(在jQuery中)
可能重复:
jQuery单选择器vs .find()
jQuery中$(Parent Child)和$(Parent).find(Child)之间有什么区别吗?
您可能有多个孩子,如:
$("div").find("span")
将返回所有子节点。 但与$("div span")
吗?
一个非常重要的区别是, $
与多个含义重载,因此在与用户定义的字符串一起使用时容易受到攻击,而find
则不然。
E. g。
$('.items .'+location.hash.substr(1)) // very bad idea $('.items').find('.'+location.hash.substr(1)) // this is OK