jquery191源码分析系列(十二)之筛选操作_jquery

jquery191源码分析系列(十二)之筛选操作_jquery

ID:30769488

大小:187.20 KB

页数:10页

时间:2019-01-03

jquery191源码分析系列(十二)之筛选操作_jquery_第1页
jquery191源码分析系列(十二)之筛选操作_jquery_第2页
jquery191源码分析系列(十二)之筛选操作_jquery_第3页
jquery191源码分析系列(十二)之筛选操作_jquery_第4页
jquery191源码分析系列(十二)之筛选操作_jquery_第5页
资源描述:

《jquery191源码分析系列(十二)之筛选操作_jquery》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、Jquery1.9.1源码分析系列(十二)之筛选操作废话不多说了直接奔入主题了。jQuery.fn.find(selector)find接受一个参数表达式selector:选择器(字符串)、D0M元素(Element)、jQuery对象。分两种情况处理:第一种,如果传入的参数是非字符串,则先通过jQuery选择器将selector查找出来,然后过滤出包含于当前jQuery对象所匹配的元素的节点。if(typeofselector!==z,string,z){self二this;returnthis.pushStack(jQuery(selector).fi1ter

2、(function(){for(i=0;i

3、$(selector,context)变成$(context).find(selector),需要去重和pushStackret二this.pushStack(len>1?jQuery.unique(ret):ret);ret.selector=(this.selector?this.selector+:"")+seiector;rcturnret;jQuery.fn.closest(selectors,context)第二个参数是可选的。函数用于从当前匹配元素开始,逐级向上级选取符合指定表达式的第一个元素,并以jQuery对象的形式返回。这里的表达式包括:选择器

4、(字符串)>D0M元素(Element)>jQuery对象。代码中的处理步骤为1.根据传递的参数先查询出结果保存在pos小。pos=rneedsContext.test(selectors)typeofselectors!=="string,z?jQuery(selectors,context

5、

6、this.context):0;2•遍历当MjQuery对象的每一个元素,从这个元素开始,逐级向上级选取符合指定表达式的第一个祖先元素。for(;i<1;i++){cur=this[i];while(cur&&cur・ownerDocumcnt&&cur!==contex

7、t&&cur・nodcTypc!==11){if(pos?pos・index(cur)>-1:jQuery.find.matchesSelector(cur,selectors)){ret.push(cur);break;}cur二cur.parentNode;}}returnthis・pushStack(ret.1ength>1?jQuery.unique(ret):ret);parents()和.closest()方法类似,它们都沿DOM树向上遍历。但区别也很大closest找到第一个符合条件就截止,parents是找到所有符合条件的集合。jQuery.fn.

8、parent/parents/parentsUntil/next/prev/nextAll/prevAll/ncxtUntil/prcvUntil/siblings/childrcn/contcnts详解以上几组筛选被放在一起处理,源码如下jQuery.each({parent:function(elem){•••},parents:function(elem){•••},parentsUnt订:function(elem,i,until){•••},next:function(elem){•••},prcv:function(clcm){•••},ncxtAll

9、:function(clcm){•••},prevAll:function(elem){•••},i,until)i,until)nextUntil:function(elem,prevUntil:function(elem,siblings:function(elem)childrcn:function(clcm)contents:function(elem)},function(name,fn){jQuery.fn[name]二function(until,selector)varret二jQuery.map(this,fn,until);〃过滤);retur

10、nthis

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。