jquery-2.1.4 源码解读(2):jQuery.fn.init 构造函数解读
2015-12-08 21:17
1056 查看
当我们用$()时就是调用new jQuery.fn.init() 生成jQuery对象。init构造函数在源码的第2735-2832行,具有两个形参,结构如下:
init()构造函数对四种情况进行处理:
1、当selector为"",null,undefined,false时,将不带自定义属性的空jQuery对象返回,代码如下:
2、当selector为string类型时,又分5种情况,代码从2744-2812:
1) 当字符串类型为<....>时
2) 对应(html, props)
3) 当字符串类型为#...时,此时对应根据id选择符进行选择时
4) 对应$(expr, $(...))时
5) 对应 $(expr, context) 时
其中第四种和第五种情况最为复杂。
3、当selector为DomElement时,代码2812-2824
4、当selector为function时,代码2828-2833
jQuery.fn.init = function(selector, context){ ... }
init()构造函数对四种情况进行处理:
1、当selector为"",null,undefined,false时,将不带自定义属性的空jQuery对象返回,代码如下:
// HANDLE: $(""), $(null), $(undefined), $( if ( !selector ) { return this; }
2、当selector为string类型时,又分5种情况,代码从2744-2812:
1) 当字符串类型为<....>时
2) 对应(html, props)
3) 当字符串类型为#...时,此时对应根据id选择符进行选择时
4) 对应$(expr, $(...))时
5) 对应 $(expr, context) 时
其中第四种和第五种情况最为复杂。
3、当selector为DomElement时,代码2812-2824
4、当selector为function时,代码2828-2833
相关文章推荐
- Jquery 中DOM对象操作
- MyEclipse中jquery.js文件报missing semicolon的错误解决
- 使用Jquery clone添加多行数据
- JQuery--隐藏和显示
- 15个值得开发人员关注的jQuery开发技巧和心得
- 模拟上传头像支持截图
- html5 jqueryrotate插件实现旋转动画
- html5 jqueryrotate插件实现旋转动画
- html5 jqueryrotate插件实现旋转动画
- jQuery 1.9 .live() is not a function
- 学习 easyui 之二:jQuery 的 ready 函数和 easyloader 的加载回调函数
- jquery的attr禁用表单元素的方法
- 带文件上传的form表单提交, jquery的ajaxfileupload+插件dropzone图文详解
- 解决 jquery 在 eclipse 里面报错的最佳方案
- jquery中方法的扩展
- General JQuery 常用控件操作
- jquery autocomplete ajxa (json list)处理
- jquery的html,text,val
- jquery分页
- js/jquery(2)