- 浏览: 252726 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
dhunter:
mongodb 需要auth 怎么加呢?
linux下mongodb+nodejs环境搭建 -
y1d2y3xyz:
xie666 写道html.push('<td alig ...
javascript DOM操作性能-----创建DOM -
xie666:
html.push('<td align="c ...
javascript DOM操作性能-----创建DOM -
轩辕丶菓菓:
bushkarl 写道那我后台用struts2,我的name一 ...
Ext表单之loadRecord用法详解 -
heikediguo:
这样不会按照你想要的顺序加载。
加载JS文件
源码95~289行,jquery.fn核心函数(utils)
init方法
init方法实际就是juqery的主函数 $()或jQuery()
$()参数:
selector: 选择器(支持字符串,dom元素,数组,函数,jQuery对象,null,undefined,false)
content : 一个待查找的 DOM 元素集、文档或 jQuery 对象。
rootjQuery : 当前文档作用域的根节点
1.jQuery()或$()
2.jQuery(element)或$(element)
3.jQuery('<tag>')或$('<tag>')
4.jQuery(#id)或$(#id)
5.jQuery(callback)或$(callback)
6.jQuery(expr, $(...))或$(expr, $(...)),如:$("div>p",$(...)),$("input:radio",document.forms[0]),$("div.foo",document.forms[0])
7.以上所有情况外的其他情况
jQuery.fn = jQuery.prototype = { constructor: jQuery, init: function( selector, context, rootjQuery ) {},//下面单独讲 // Start with an empty selector selector: "", // The current version of jQuery being used jquery: "1.8.2",//当前版本 // The default length of a jQuery object is 0 length: 0,//定义jquery初始化对象的长度 // The number of elements contained in the matched element set size: function() {},//返回当前对象长 toArray: function() {},//数组转换 // Get the Nth element in the matched element set OR // Get the whole matched element set as a clean array get: function( num ) {},//获取jquery对象中的第num+1个元素 // Take an array of elements and push it onto the stack // (returning the new matched element set) pushStack: function( elems, name, selector ) {},//将DOM集合元素elems添加jquery栈中 // Execute a callback for every element in the matched set. // (You can seed the arguments with an array of args, but this is // only used internally.) each: function( callback, args ) {},//见jQuery.each ready: function( fn ) {},//见jQuery.ready.promise() eq: function( i ) {},//返回第i+1个元素 first: function() {},//返回第一个元素 last: function() {},//返回最后一个元素 slice: function() {}, map: function( callback ) {}, end: function() {}, // For internal use only. // Behaves like an Array's method, not like a jQuery method. push: core_push, sort: [].sort, splice: [].splice }; // Give the init function the jQuery prototype for later instantiation jQuery.fn.init.prototype = jQuery.fn;
init方法
init方法实际就是juqery的主函数 $()或jQuery()
$()参数:
selector: 选择器(支持字符串,dom元素,数组,函数,jQuery对象,null,undefined,false)
content : 一个待查找的 DOM 元素集、文档或 jQuery 对象。
rootjQuery : 当前文档作用域的根节点
init: function( selector, context, rootjQuery ) { var match, elem, ret, doc; // Handle $(""), $(null), $(undefined), $(false) if ( !selector ) { return this; } // Handle $(DOMElement) 一个参数,且为DOM元素 $(body) if ( selector.nodeType ) { this.context = this[0] = selector; this.length = 1; return this; } // Handle HTML strings //html字符串 if ( typeof selector === "string" ) {//'<tag>'形式字符串 如 $('<input>') if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { // Assume that strings that start and end with <> are HTML and skip the regex check match = [ null, selector, null ]; } else {//含html的字符串或含#id形式的字符串 match = rquickExpr.exec( selector ); } // Match html or make sure no context is specified for #id if ( match && (match[1] || !context) ) { //如 $("<div><p>Hello</p></div>") // HANDLE: $(html) -> $(array) if ( match[1] ) { context = context instanceof jQuery ? context[0] : context; doc = ( context && context.nodeType ? context.ownerDocument || context : document ); // scripts is true for back-compat selector = jQuery.parseHTML( match[1], doc, true ); if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { this.attr.call( selector, context, true ); } return jQuery.merge( this, selector ); // HANDLE: $(#id) } else { elem = document.getElementById( match[2] ); // Check parentNode to catch when Blackberry 4.6 returns // nodes that are no longer in the document #6963 if ( elem && elem.parentNode ) { // Handle the case where IE and Opera return items // by name instead of ID if ( elem.id !== match[2] ) { return rootjQuery.find( selector ); } // Otherwise, we inject the element directly into the jQuery object this.length = 1; this[0] = elem; } this.context = document; this.selector = selector; return this; } // HANDLE: $(expr, $(...)) } else if ( !context || context.jquery ) { return ( context || rootjQuery ).find( selector ); // HANDLE: $(expr, context) // (which is just equivalent to: $(context).find(expr) } else { return this.constructor( context ).find( selector ); } // HANDLE: $(function) // $(function(){ //Document is ready //}); // Shortcut for document ready } else if ( jQuery.isFunction( selector ) ) { return rootjQuery.ready( selector ); } if ( selector.selector !== undefined ) { this.selector = selector.selector; this.context = selector.context; } return jQuery.makeArray( selector, this ); }
1.jQuery()或$()
//Handle $(""), $(null), $(undefined), $(false), $() if ( !selector ) { return this;//返回该对象 }
2.jQuery(element)或$(element)
// Handle $(DOMElement) 一个参数,且为DOM元素 $(body) if ( selector.nodeType ) { this.context = this[0] = selector;//设置该对象的context属性为该DOM元素 this.length = 1; return this; }
3.jQuery('<tag>')或$('<tag>')
// Handle $('<input>',document.forms[0]) // 匹配类似"ddd<a href='www.sina.com'>新浪网</a>asd" 格式,返回match[1]的值为"<a href='www.sina.com'>新浪网</a>" if ( match[1] ) { context = context instanceof jQuery ? context[0] : context;//context参数是否jQuery实例 //获取上下文,当上下文为DOM元素时,则为根节点,否则为document文档 doc = ( context && context.nodeType ? context.ownerDocument || context : document ); // scripts is true for back-compat selector = jQuery.parseHTML( match[1], doc, true ); if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { this.attr.call( selector, context, true ); } return jQuery.merge( this, selector ); }else{ // }
4.jQuery(#id)或$(#id)
{ //match[2]为匹配#id的格式,如果match[2]不为空则返回id的字符表示,如“#name”则match[2]值为“name” elem = document.getElementById( match[2] ); // Check parentNode to catch when Blackberry 4.6 returns // nodes that are no longer in the document #6963 if ( elem && elem.parentNode ) { // Handle the case where IE and Opera return items // by name instead of ID //由于IE和Opera浏览器在调用getElementById方法时用会同时把name相同的属性找出来,所以针对这中情况就利用name属性方式查找 if ( elem.id !== match[2] ) { return rootjQuery.find( selector ); } // Otherwise, we inject the element directly into the jQuery object this.length = 1; this[0] = elem; } this.context = document; this.selector = selector; return this; }
5.jQuery(callback)或$(callback)
return rootjQuery.ready( selector );//当参数类型为function时
6.jQuery(expr, $(...))或$(expr, $(...)),如:$("div>p",$(...)),$("input:radio",document.forms[0]),$("div.foo",document.forms[0])
if ( !context || context.jquery ) { return ( context || rootjQuery ).find( selector );// }
7.以上所有情况外的其他情况
// HANDLE: $(expr, context) return this.constructor( context ).find( selector );
发表评论
-
jquery validation使用说明
2014-05-05 22:50 681http://www.cnblogs.com/hejunrex ... -
jquery源码-jQuery.callback()
2013-03-12 17:21 0源码919~1099行,该函数主要是对callback的fn进 ... -
jquery源码-jquery.ready.promise(obj)
2013-03-04 22:33 0jQuery.ready.promise = functi ... -
jquery源码-jquery基本操作函数(utils)
2013-02-21 14:06 3585源码355~905行,这一节的源码部分比较长,不会对所有的代码 ... -
jquery源码-jquery.extend()
2013-02-14 12:36 1791源码291~353行,jQuery.extend函数(util ... -
jquery源码-jquery变量定义
2013-02-10 15:08 2768源码 15~93行,jquery变量定义 var // ... -
jquery源码-代码结构
2013-02-08 15:09 1235/*! * jQuery JavaScript L ... -
jquery源码-框架入口
2013-02-06 17:48 1312从Jquery整个代码看,入口就是一个自执行的闭包函数 ... -
javascript实现自动换列
2011-11-03 12:25 1582在应用Extjs的桌面应用desktop中遇到这个问题,图标需 ... -
构造函数作用域的安全
2011-10-30 23:48 1215在创建javascrip对象的时候,我们用得最多的写法可能就是 ... -
javascript DOM操作性能-----创建DOM
2011-10-30 22:57 1680在很多时候我们都需要创建一系列的元素节点,就像如下的操作一样: ... -
javascript闭包应用之匿名函数
2011-09-24 13:22 1636今天看到javascrip组有问朋友问 (function() ... -
Javascript之prototype 原型重写
2011-09-19 23:07 1794function Person(){} var pe ... -
Javascript之Number
2011-09-15 00:31 1350//一切从基础开始,之 ... -
Javascript之Undefined和null
2011-09-13 22:01 763var abc = null; alert(typeof ... -
Javascript之Undefined你可能不知道的
2011-09-13 21:43 1083var abc ; alert(abc);// ... -
js中event对象集合
2011-08-26 22:42 1262JS中判断鼠标按键的问 ... -
contains和compareDocumentPosition 方法来确定是否HTML节点间的关系
2011-08-04 21:26 1051一个很棒的 blog 文章 ... -
一个简单的AJAX类
2011-04-26 17:35 951<!DOCTYPE html PUBLIC &quo ... -
JS获取页面中节点的位置
2011-04-26 13:55 1843<!DOCTYPE html PUBLIC &quo ...
相关推荐
jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery...jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQuery源码jQue
jQuery-, jQuery源码解读 -- jQuery v1.10.2
锋利的jQuery---附源码
jQuery源码分析-插件
不要分,下吧. 我网速问题..打不开jquery网站,存下来备用
jquery-easyui-1.2.4源码,在其他地方是没有的,内部发布
jquery源码分析(2.0.3版本) 大概内容大纲 (功能(){ (21,94)定义了一些变量和函数jQuery = function(){} (96,284)给JQ对象添加一些方法和属性 (285,347)扩展名:JQ的继承方法 (349,817)jQuery....
jquery-easyui-1.3.3源码 未压缩,包含完整源文件,方便大家学习。
jQuery源码分析-事件(1).
jquery-easyui-1.7.0 官方文档以及源码,演示demo,内容详细
Jquery详解-源码分析
jquery-ui-1.9.2.custom.min.js源码文件,文件需要国外下载,因为下载过了,有需要可以直接拿去用,加快开发进度,不要为了下载文件而党务过多的时间。
jquery-easyui-1.2.5源码
jquery-3.3.1.js/min.js
jquery-migrate-3.0.0.min.js 含源码 包含以下文件: jquery-migrate-3.0.0.min.js jquery-migrate-3.0.0.js // 这个是源码哦 截至2017.11.21, jQuery3.x 最新最稳定版本
商业源码-编程源码-JQuery构建可拖曳购物车源码.zip
精通JavaScript+jQuery电子书+源码-部分3,源码在第5部分
jQuery源码分析-初步
JavaScript和jQuery实战手册源码--the missing manual示例代码合集
jquery-3.1.1.min.js