码迷,mamicode.com
首页 > 其他好文 > 详细

find()与children()方法的区别

时间:2015-08-17 15:14:48      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

来源:http://www.jb51.net/article/26195.htm

 

总经一下前段时间用于的jQuery方法:find及children。需要的朋友可以参考下。

 

首先看看英文解释吧: 
children方法:
技术分享
find方法:
技术分享
通过以上的解释,可以总结如下: 
1:children及find方法都用是用来获得element的子elements的,两者都不会返回 text node,就像大多数的jQuery方法一样。 
2:children方法获得的仅仅是元素一下级的子元素,即:immediate children。 
3:find方法获得所有下级元素,即:descendants of these elements in the DOM tree 
4:children方法的参数selector 是可选的(optionally),用来过滤子元素,但find方法的参数selector方法是必选的。 
5:find方法事实上可以通过使用 jQuery( selector, context )来实现:英语如是说:Selector context is implemented with the .find() method; therefore, $(‘li.item-ii‘).find(‘li‘) is equivalent to $(‘li‘, ‘li.item-ii‘). 

例如,有以下html元素: 
技术分享
使用:$(‘ul.level-2‘).children().css(‘border‘, ‘1px solid green‘); 的效果是: 
技术分享
使用 $(‘ul.level-2‘).find(‘li‘).css(‘border‘, ‘1px solid green‘); 的效果是: 
技术分享

find()与children()方法的区别

标签:

原文地址:http://www.cnblogs.com/morning0529/p/4736596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!