教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jQuery初学:find()方法及children方法的区别分析

jQuery初学:find()方法及children方法的区别分析

发布时间:2013-07-16   编辑:jiaochengji.com
总经一下前段时间用于的jQuery方法:find及children。需要的朋友可以参考下。
总经一下前段时间用于的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'); 的效果是:

您可能感兴趣的文章:
jQuery初学:find()方法及children方法的区别分析
用示例说明filter()与find()的用法以及children()与find()的区别分析
Jquery children与find的区别分析
jQuery父级以及同级元素查找介绍
Jquery中children与find之间的区别详细解析
jQuery find与children方法示例
jquery的父子兄弟节点查找示例代码
基于jquery中children()与find()的区别介绍
jQuery基础知识filter()和find()实例说明
jquery查找子节点的方法总结

[关闭]
~ ~