jQuery初学:find()方法及children方法的区别分析
更新时间:2011年01月31日 23:19:42 作者:
总经一下前段时间用于的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'); 的效果是:
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 (七) jQuery动画实现 让页面动起来
开发人员一直痛疼做动画. 但是有了jQuery你会瞬间成为别人(那些不知道jQuery的人)眼里的动画高手! 本文将介绍jQuery的动画相关函数.原来做动画如此简单!2011-02-02jcarousellite.js 基于Jquery的图片无缝滚动插件
基于Jquery的图片无缝滚动插件,需要的朋友可以参考下。2010-12-12基于jQuery UI CSS Framework开发Widget的经验
jQuery UI CSS Framework是jQuery UI中的一个样式框架,可以利用jQuery Theme roller 来生成自己想要的css样式效果。我们可以利用jQuery UI的一些框架来开发出基于jQuery UI CSS Framework效果的插件来。2010-08-08
最新评论