/*!* Includes Sizzle.js    选择器,独立的库* http://sizzlejs.com/*/(function( window, undefined ) {//"use strict";
var//rootjQuery = jQuery(document) = $();压缩有用
rootjQuery,//dom是否加载完
readyList,//core_strundefined == 'undefined'core_strundefined = typeofundefined,//Use the correct document accordingly with window argument (sandbox)location =window.location,document=window.document,docElem=document.documentElement,//接受外部对jQuery,$的改变,报讯在_jQuery,_$中,_jQuery =window.jQuery,_$=window.$,//class2type = { '[Object String]' : 'string' , '[Object Array]' : 'array' }class2type ={},//没有用处core_deletedIds =[],core_version= "2.0.3",//将对象方法的地址保存在变量中,后面用call调用。/*var    core_deletedIds = [],core_version = "2.0.3",core_push = core_deletedIds.push,core_trim = core_version.trim;alert(core_push);function F(){this.pu = core_push;this.tr = core_trim;this.ar = new Array();this.df = function(){}}var f1 = new F();core_push.call(f1.ar,1,2,3,4);f1.pu.call(f1.ar,1,2,3,4)//f.ar.core_push(1,2,3,4);  //f.ar没有core_push方法alert(f1.ar.toString());var f2 = new F();alert(f2.pu === f1.pu);//TRUEalert(f2.df === f1.df);//falsealert(f2.tr === f1.tr);//TRUEalert(f2.ar === f1.ar);//falsefunction F(){this.a = 1;this.f = function(){alert(2);}}var f1 = new F();var f2 = new F();alert(f1.f == f2.f);//falsevar f1f = f1.f;function N(){this.f = f1f;}var n1 = new N();var n2 = new N();alert(n1.f == n2.f);//truealert(n1.f === n2.f);//true*/core_concat=core_deletedIds.concat,core_push=core_deletedIds.push,core_slice=core_deletedIds.slice,core_indexOf=core_deletedIds.indexOf,core_toString=class2type.toString,core_hasOwn=class2type.hasOwnProperty,core_trim=core_version.trim,//[]表示任意一个,?表示0、1个,\d表示数字,*表示任意多个,.单个非回车换行的字符,\.字符点,|是或者,\d*\.| 数字加小数点或者什么都没有,[eE]科学计数法core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,//\S是空格core_rnotwhite = /\S+/g,//正则中不加g的时候,会把整体匹配到还会匹配整项,?:表示外层的括号不是子项,小括号是2个子项,//match = ['#div1',null,'div1'];  //$('#div1')rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]* | #([\w-]*))$/,//匹配空标签<p></p>rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,//Matches dashed string for camelizingrmsPrefix = /^-ms-/,rdashAlpha= /-([\da-z])/gi,//Used by jQuery.camelCase as callback to replace()fcamelCase = function( all, letter ) {returnletter.toUpperCase();},//匿名函数全局作用域,dom加载完成执行的方法completed = function() {document.removeEventListener("DOMContentLoaded", completed, false);window.removeEventListener("load", completed, false);jQuery.ready();};/*function Aaa(){}Aaa.prototype.init = function(){};Aaa.prototype.css = function(){};var a1 = new Aaa();a1.init();//prototype里的方法一般用对象调用a1.css();function jQuery(){return new jQuery.prototype.init();//返回init类的对象}jQuery.prototype.init = function(){};jQuery.prototype.css = function(){};jQuery.prototype.init.prototype = jQuery.prototype;//init类的原型等于jQuery的原型,init对象就可以使用jQuery原型里的方法//外部使用jQuery().css();*///$() == jQuery(),这个函数返回对象,
jQuery = function( selector, context ) {//jQuery.fn=jQuery.prototype={init:function(){}},fn就指向prototype,init就是prototype里面的方法,一般用类的对象来调用。//jQuery()、$()返回的是init()类的对象,并且执行了init函数里面的方法,执行初始化。//$(),jQuery()传的参数都是传给了init()方法里面去了return newjQuery.fn.init( selector, context, rootjQuery );},
jQuery.fn.init.prototype= jQuery.fn;//init类的原型等于jQuery的原型,init对象就可以使用jQuery原型里的方法
jQuery.fn= jQuery.prototype = {            //给类jQuery增加静态属性fn,修改函数的prototype并增加属性和方法
jquery: core_version,constructor: jQuery,//不回指就是object//$("a,b,c")都是调用的是init方法,new init(a,b,c),//$('li','ul')//选择ul下面的li,//return new jQuery.fn.init(),init函数执行,如果有return就返回return里面的东西(return的要是引用对象,否则返回init类的实例对象)。init: function( selector, context, rootjQuery ) {varmatch, elem;//$(""), $(null), $(undefined), $(false) 判空if ( !selector ) {return this;//返回init函数类的对象
}//$('#div1') $('.box') $('div')  $('#div1 div.box') $('<li>')  $('<li>1</li><li>2</li>')//创建字符串标签,$('li','ul')//选择ul下面的li, 都是strings类型。if ( typeof selector === "string") {if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3) {//标签<p>,match是进来的时候定义的,拼接数组,//$('<li>')   $('<li>1</li><li>2</li>')//match = [ null, '<li>', null ];//match = [ null, '<li>1</li><li>2</li>', null ];match = [ null, selector, null];}else{/*不是标签,$('#div1') $('.box') $('div')  $('#div1 div.box') $('<li>hello')rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]* | #([\w-]*))$/,match = null;  //$('.box') $('div')  $('#div1 div.box')match = ['#div1',null,'div1'];  //$('#div1')match = ['<li>hello','<li>',null];  //$('<li>hello')*/match=rquickExpr.exec( selector );}//创建标签或者根据id查找,$('<li>')  $('#div1')if ( match && (match[1] || !context) ) {//创建标签 $('<li>')if ( match[1] ) {//第二个参数context是创建标签的上下文,$('<li>',$(document)),用于iframe中,context = context instanceof jQuery ? context[0] : context;//$('<li>1</li><li>2</li>').appendTo( ' ul ' );//merge方法 把 $('<li>1</li><li>2</li>')变成json = {0 : 'li',1 : 'li',length : 2},return this就是这个json并返回出去,就可以appendTo到ul上了。$()返回你需要的任意类型this对象。jQuery.merge( this, jQuery.parseHTML(//parseHTML方法把<li>1</li><li>2</li>变成li数组[li,li],match = [ null, '<li>1</li><li>2</li>', null ];//new的时候this指的是本类对象,match[1],context&& context.nodeType ? context.ownerDocument ||context : document,true) );//添加标签并且加属性,$('<li></li>',{title : 'hi',html : 'abcd',css : {background:'red'}}).appendTo( 'ul' );//rsingleTag正则匹配单标签。<li>、<li></li>可以,<li></li><li></li>不行,isPlainObject判断第二个参数是jsonif ( rsingleTag.test( match[1] ) &&jQuery.isPlainObject( context ) ) {for ( match incontext ) {//{html:abcd},this[html]是一个函数,就执行这个函数this[html]('abcd'),if ( jQuery.isFunction( this[ match ] ) ) {this[ match ]( context[ match ] );//{title:'hi'},this.attr(title,'hi'),} else{this.attr( match, context[ match ] );}}}return this;//$('#div1') ,id选择器,match = ['#div1',null,'div1'];} else{elem= document.getElementById( match[2] );//根据id获取element,//Blackberry 4.6仅仅判断elem存在是不行的,还要判断他父节点存在if ( elem &&elem.parentNode ) {//Inject the element directly into the jQuery objectthis.length = 1;this[0] = elem;//给对象添加属性名为0值为elem,this[0]设置获取值,不能通过this.0设置获取值。/*function F(a){return new init();//this是F对象}function init(a){this.length = 1;this[0] = document.getElementById("a");alert(this[0].innerHTML);return this;}var f = F();alert(f[0].innerHTML);*/}this.context =document;this.selector = selector;//'#div1'return this;}//HANDLE: $(expr, $(...))//jquery: core_version = "2.0.3",} else if ( !context ||context.jquery ) {//context不存在或者context存在且context的jquery存在//( context || rootjQuery )context存在不走后面,rootjQuery  = jQuery(document),context.find()  或者  rootjQuery.find//$('ul',$(document)).find('li');走这里,$(document)是init对象有jquery属性,jquery是init方法的属性,就是判断context是不是init对象或者说jQuery对象。return ( context ||rootjQuery ).find( selector );//HANDLE: $(expr, context)//(which is just equivalent to: $(context).find(expr)} else{//context存在并且context的jquery属性不存在//$('ul',document).find('li');走这里//constructor: jQuery,constructor就是jQuery函数,jQuery(document).find,window.$ = jQuery;相当于$(document).find,//constructor和函数名一样,都是指的是函数地址,return this.constructor( context ).find( selector );}//selector !== "string" : $(DOMElement),$(this)  $(document)} else if ( selector.nodeType ) {//节点都有nodeType属性this.context = this[0] =selector;this.length = 1;return this;//HANDLE: $(function)  $(function(){})//$(function(){}) 是后面的简写 $(document).ready(function(){});} else if( jQuery.isFunction( selector ) ) {//rootjQuery = jQuery(document);returnrootjQuery.ready( selector );}//$([])  $({})  $( $('#div1') ) ===  $('#div1') ,如果传的是jquery对象$('#div1') ,selector = $('#div1'),$('#div1')这个对象有selector属性,selector.selector === '#div1',if ( selector.selector !==undefined ) {this.selector = selector.selector;//'#div1'this.context = selector.context;//document
}return jQuery.makeArray( selector, this );//把类似于数组的转成真正的数组,
},//选择到的元素的字符串selector: "",//$('') 返回的new init(),是init对象,或者init方法中返回的引用对象,对象中元素的个数,length: 0,//jQuery函数原型的方法,jQuery函数对象的方法,makeArray是jQuery extend的方法//$('div')) : json对象 Object { 0: <div>, 1: <div>, 2: <div>, 3: <div>, length: 4, prevObject: Object, context: HTMLDocument → new%202.html, selector: "div" }//$('div').toArray() : Array [ <div>, <div>, <div>, <div> ]toArray: function() {//json转数组return core_slice.call( this);},//$('div').get(-1).innerHTML = '222222222',$('div')是jQuery返回的this对象,$('div').get()返回的是div的数组,this[ num ]中括号除了数组的下标还可以代表json或者对象的属性。get: function( num ) {return num == null ?this.toArray() :( num< 0 ? this[ this.length + num ] : this[ num ] );},//Take an array of elements and push it onto the stack (returning the new matched element set)//$('div').pushStack( $('span') )pushStack: function( elems ) {/*jQuery = function() {alert(1);return new jQuery.fn.init();},jQuery.fn = jQuery.prototype = {//fn是类的静态属性//能够调用jQuery原型里(constructor()、pushStack())方法的只能是jQuery对象或者init对象:$('div')。constructor: jQuery,init: function() {},//$('div').pushStack,this是$('div'),pushStack: function() {alert(2);this.constructor();//1,  this是init对象或者jQuery对象$('div'),返回的是新的空init对象constructor();//constructor.call(window),调不了报错,},}jQuery.fn.init.prototype = jQuery.fn;var j = constructor();//window调用不了$('div').pushStack();//1,2,1, $('div')是init对象可以调用pushStack()方法o = {}o.pushStack();//o.pushStack is not a function,能够调用pushStack方法是jQuery的对象后者init对象,new jQuery.fn.init().pushStack();//2 1*///this是调用pushStack方法的对象,能够调用pushStack和constructor()方法的只有jQuery的对象后者init对象,这里this是$('div')(json格式),this.constructor()返回的是新的空参数的init对象(有jQuery原型的属性和方法以及init函数类的属性方法)var ret = jQuery.merge( this.constructor(), elems );//返回span集合,elems = $('span')ret.prevObject = this;//this = $('div'),$('span').prevObject -> $('div')ret.context = this.context;return ret;//将$('span')返回出去/*$('div').pushStack( $('span') ),pushStack()返回span,span的prevObject等于div,css('background','red')只会把span变红,end: function() {return this.prevObject || this.constructor(null);},调用end方法就是返回prevObject就实现了栈,多次调用end(),最后返回空,就不处理最后的css方法。$('div').pushStack( $('span') ).css('background','red').end().end().end().css('background','yellow');*/},//加强版的for循环,each是原型的方法,就是对象的方法,each: function( callback, args ) {return jQuery.each( this, callback, args );//这个each是jQuery.extend({})加进去的,
},ready:function( fn ) {jQuery.ready.promise().done( fn );return this;},/*core_slice = core_deletedIds.slice,        core_deletedIds = [],$('div').slice(1,3)返回2.3两个div,他的prevObject = $('div')(4个div),css('background','red')就是把2个div变红,end().css('color','blue')把4个div变蓝。$('div').slice(1,3).css('background','red').end().css('color','blue');*/slice:function() {return this.pushStack( core_slice.apply( this, arguments ) );},first:function() {return this.eq( 0);},last:function() {return this.eq( -1);},//$('div').eq(0).css('background','red');eq: function( i ) {var len = this.length,//4个divj = +i + ( i < 0 ? len : 0);return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );//返回div[0],div[0].prevObject = $('div')(4个div),
},/*var arr = ['a','b','c'];arr = $.map(arr,function(elem,i){return elem + i;});alert( arr );//[a0,b1,c2]*/map:function( callback ) {return this.pushStack( jQuery.map(this,function( elem, i ) {returncallback.call( elem, i, elem );}));},end:function() {return this.prevObject || this.constructor(null);},//内部使用,把数组的方法挂载到了jQuery对象上了,push: core_push,//core_push = core_deletedIds.push,core_deletedIds = [],
sort: [].sort,splice: [].splice
};//给jQuery类添加静态方法extend,给jQuery的原型添加方法就是添加对象的方法/*$.extend({     //给jQuery类加静态方法aaa : function(){alert(1);},bbb : function(){alert(2);}});$.fn.extend({     //给jQuery对象加方法aaa : function(){alert(3);},bbb : function(){alert(4);}});$.aaa();//1$.bbb();//2$().aaa();//3$().bbb();//4
$.extend();  -> this -> $(jQuery类)  -> this.aaa  ->  $.aaa()
$.fn.extend(); -> this -> $.fn(jQuery原型对象) -> this.aaa ->  $().aaa()//当写多个对象自变量的时候 , 后面的对象都是扩展到第一个对象身上var a = {};$.extend( a , { name : 'hello' } , { age : 30 } );console.log( a );//  { name : 'hello'  ,  age : 30 }    深拷贝浅拷贝*/jQuery.extend= jQuery.fn.extend = function() {//extend继承方法的定义,extend就是给自变量的对象或者jQuery类jQuery对象扩展另一个对象的属性。就是涉及到深拷贝浅拷贝。varoptions, name, src, copy, copyIsArray, clone,//默认目标元素是第一个参数,arguments[0],i = 1,不做深拷贝deep = false;//var a = {};$.extend( a , { name : 'hello',age:12 } , { ss : 30 }target = arguments[0] || {},//第一个参数i = 1,length=arguments.length,deep= false;//默认是浅拷贝/*深拷贝var a = {};var b = {  name : { age : {nn:14} } };$.extend( true,a , b );*/if ( typeof target === "boolean" ) {//判断第一个参数是不是布尔值deep = target;//true 深拷贝target = arguments[1] || {};//目标元素是第二个参数i = 2;//目标元素是第二个参数
}//第一个元素不是对象也不是函数,是string或其他,有可能是深拷贝,设置目标元素是空对象if ( typeof target !== "object" && !jQuery.isFunction(target) ) {target={};}//只有一个参数,$.extend({aaa : function(){alert(1);},bbb : function(){alert(2);}),$.fn.extend({aaa : function(){alert(1);},bbb : function(){alert(2);})
});if ( length ===i ) {target= this;//目标参数就是this,this是$或者$.fn,this指的是函数时候代表函数体,--i;//i=0
}//多个参数,循环把每个对象赋值到第一个对象,//1.var a = {};$.extend( a , { name : 'hello',age:12 } , { ss : 30 } );target=a,deep = false,i = 1,//2.$.extend({aaa : function(){alert(1);},bbb : function(){alert(2);}),i=0,deep = false//3.1.var a = {}; var b = {  name : {age : {nn:14} } }; $.extend( true,a , b );deep = true,target=a={},i = 2for ( ; i < length; i++) {//1.判空,不能是$.extend( a , null , null ); 1.options是第i个json,//2.options={aaa : function(){alert(1);},bbb : function(){alert(2);}//3.1.options= {  name : { age : {nn:14} } }if ( (options = arguments[ i ]) != null) {//1.遍历第i个json,{ name : 'hello',age:12 }for ( name inoptions ) {//1.target = a = {},src = a[name] = null,a[age] = null,a[ss]=null//2.$[aaa]=null=src,target=$,$[bbb]=null=src//3.1.a[name]=src=null,src =target[ name ];//1.copy = 'hello' copy=12 copy=30//2.copy=function(){alert(1);},copy=function(){alert(2);},//3.1.copy={age : {nn:14} }copy =options[ name ];//1. $.extend( a , { name : a } )防止这种情况//2.$.extend({aaa : $,bbb : $)防止这种情况//3.1.$.extend( true,a , {name:a} )if ( target ===copy ) {continue;}//深拷贝//3.1.isPlainObject判断json键对应的值是不是对象,或者数组//copy这个键的值是对象if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray =jQuery.isArray(copy)) ) ) {//src = target[ name ] 如果存在,target[ name ] = jQuery.extend( deep, target[ name ], copy );if( copyIsArray ) {copyIsArray= false;clone= src && jQuery.isArray(src) ?src : [];}else{/*3.1.3 clone=falsevar a = { name : { job : 'it' } };var b = { name : {age : {n:10}} };$.extend( true , a  , b );            src = { job : 'it' }a = { name : { job : 'it' ,{age : {n:10}}} };*/clone= src && jQuery.isPlainObject(src) ?src : {};}//3.递归//3.1.a[name]=jQuery.extend( true, {}, {age : {nn:14} } )//3.1.2 a[name]=jQuery.extend( true, { job : 'it' }, {age : {n:10}})//3.1.2 a[age]=jQuery.extend( true, {}, {n:10} )={n:10},a={job : 'it',age : {n:10}}//3.1.3 a[name] = jQuery.extend( true, { job : 'it' }, {age : {n:10}} );   target={job : 'it'}  target[age]=jQuery.extend( deep, {}, {n:10} );target={}  target[n]=10 return{n:10},target[age]={n:10},target={job : 'it',age : {n:10}} return target,a[name]={job : 'it',age : {n:10}}target[ name ] =jQuery.extend( deep, clone, copy );//浅拷贝target[ name ] = copy;copy是一个对象的时候就是传递的地址,} else if ( copy !==undefined ) {//1.a[name] = 'hello' a[age] = 12 a[ss]=30 a={name:'hello',age:12,ss:30}//2.$[aaa]=function(){alert(1);},$[bbb]=function(){alert(2);}target[ name ] =copy;}}}}returntarget;
};jQuery.extend({//调用extend方法,给jQuery函数增加静态方法,js中直接通过$调用,不需要jquery对象。//唯一随机字符串,replace( /\D/g, "" )把非数字小数点变为空,例如数据缓存做唯一操作expando: "jQuery" + ( core_version + Math.random() ).replace( /\D/g, ""),/*<script>
var $ = 123;
var jQuery = 456;
js源码里面有    _jQuery = window.jQuery,_$ = window.$,接受外部的改变,保存在_$ = 123,_jQuery=456
</script>
<script src="jquery-203.js"></script>
<script>
var miaov = $.noConflict(true);
</script>*/noConflict:function( deep ) {if ( window.$ === jQuery ) {//一定相等window.$ = _$;//window.$ = 123,jQuery就放弃$了,使用miaov,
}if ( deep && window.jQuery === jQuery ) {//一定相等window.jQuery = _jQuery;//window.jQuery = 456,jQuery就放弃jQuery了,使用miaov,
}returnjQuery;},//Is the DOM ready to be used? Set to true once it occurs.isReady: false,//A counter to track how many items to wait for before//the ready event fires. See #6781readyWait: 1,/*$.getScript('a.js',function(){//动态加载js,异步加载,有可能alert(2)先于a.js加载完});$(function(){alert(2);});-----------------------------------------$.holdReady(true);$.getScript('a.js',function(){//动态加载js,异步加载$.holdReady(false);//a.js加载完后回调函数执行,释放hold,保证先加载a.js,然后弹出alert(2)});$(function(){alert(2);});*/holdReady:function( hold ) {if( hold ) {jQuery.readyWait++;//readyWait是将要加到jQery函数的属性,加完之后调用这个方法就可以使用这个变量,holdReady调用多次,readyWait++多次} else{jQuery.ready(true );//下面
}},//$.ready()  Handle when the DOM is readyready: function( wait ) {//--jQuery.readyWait不为0就继续等if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {return;}//isReady是给jQuery类扩展的静态属性jQuery.isReady = true;//If a normal DOM Ready event fired, decrement, and wait if need beif ( wait !== true && --jQuery.readyWait > 0) {return;}//If there are functions bound, to execute
readyList.resolveWith( document, [ jQuery ] );//Trigger any bound ready eventsif( jQuery.fn.trigger ) {jQuery( document ).trigger("ready").off("ready");}},//See test/unit/core.js for details concerning isFunction.//Since version 1.3, DOM methods and functions like alert//aren't supported. They return false on IE (#2968).isFunction: function( obj ) {return jQuery.type(obj) === "function";},isArray: Array.isArray,isWindow:function( obj ) {//$.isWindow(window),通过$调用。js中window有2个作用,1是充当全部对象,2是做浏览器窗口,只有window才有window属性并且等于window。如果obj是undefined、null,undefined === undefined.window=undefined,null === null.window=undefined,所以要判断obj不是undefined或者null(obj != null)。return obj != null && obj === obj.window;//undefined是等于null的,null是等于null的,undefined.window返回null,null.window返回null,
},//不能用typeof,alert( typeof NaN );//numberisNumeric: function( obj ) {//parseFloat(obj) 可以转的是数字,不可以转的返回NaN,//isFinite是原生的方法,判断是不是有限的数字,alert( isFinite( Number.MAX_VALUE + Number.MAX_VALUE ) );//falsereturn !isNaN( parseFloat(obj) ) &&isFinite( obj );},type:function( obj ) {if ( obj == null ) {//obj = null或者undefinedreturn String( obj );//'undefined','null'
}//core_toString = {}.toString,//alert( {}.toString.call([]));//[object Array]这个判断类型最全//jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); });将[object Array]简写成arrayreturn typeof obj === "object" || typeof obj === "function" ?class2type[ core_toString.call(obj) ]|| "object":typeofobj;},//判断是否对象自变量isPlainObject: function( obj ) {//jQuery.type( obj ) !== "object"  不是基本类型//obj.nodeType 是一个dom节点,jQuery.type(dom节点)返回object,不是对象自变量,window也不是对象自变量,jQuery.type(window)返回objectif ( jQuery.type( obj ) !== "object" || obj.nodeType ||jQuery.isWindow( obj ) ) {return false;}//jQuery.type( window.location) 返回object,不是基本类型不是节点不是window,//有constructor属性,core_hasOwn = {}.hasOwnProperty方法,obj.constructor.prototype有没有isPrototypeOf属性,try{if ( obj.constructor &&!core_hasOwn.call( obj.constructor.prototype, "isPrototypeOf") ) {return false;}}catch( e ) {return false;//狐火下执行次数过多会报错
}//{},new Object(),return true;},//是否为空对象{},[],没有自身的属性和方法(有原型属性也可以遍历出来,不是空对象)isEmptyObject: function( obj ) {varname;for ( name inobj ) {return false;}return true;},error:function( msg ) {//$.error('这是错误');throw newError( msg );},/*keepScripts = true, 可以解析script标签把 $('<li>1</li><li>2</li>')变成this = {0 : 'li',1 : 'li',length : 2},data = [ null, '<li>1</li><li>2</li>', null ];/*var str = '<li></li><li></li>';$.parseHTML(str); 返回li的数组/*[li, li]0: li1: lilength: 2__proto__: Array(0) //var str = '<li></li><li></li><script><\/script>';$.parseHTML(str,document,true);//[li, li, script]0: li1: li2: scriptlength: 3__proto__: Array(0)//*/parseHTML:function( data, context, keepScripts ) {if ( !data || typeof data !== "string" ) {//存不存在,是不是字符串return null;}if ( typeof context === "boolean" ) {//第二个参数就是布尔值,就当第三个参数用,第二个参数是false,keepScripts =context;context= false;}context= context || document;//执行上下文只能是document,这个document可以是当前页面的也可以是iframe的,var parsed = rsingleTag.exec( data ),//判断是不是单标签<li></li>,<li></li><li></li>是多标签scripts = !keepScripts &&[];//单标签,创建这个标签,返回数组,if( parsed ) {return [ context.createElement( parsed[1] ) ];//context是执行上下文,是document对象,创建element和getelement前面都需要这个对象来调用方法而已。
}//多标签,创建dom标签节点parsed =jQuery.buildFragment( [ data ], context, scripts );if ( scripts ) {//keepScripts=true,不删除script标签,keepScripts=false,删除script标签。
jQuery( scripts ).remove();}returnjQuery.merge( [], parsed.childNodes );},//json格式字符串转json,IE678不支持,
parseJSON: JSON.parse,//Cross-browser xml parsing,解析xml,出了json解析还有xml解析,xml是最早的数据形式,后来才有的json,以前都是xml。parseXML: function( data ) {varxml, tmp;if ( !data || typeof data !== "string" ) {//不存在不是stringreturn null;}//Support: IE678不支持,支持IE9。IE678出错了不会进入catch,而是创建一个xml携带<parsererror>错误的信息</parsererror>try{tmp= new DOMParser();//创建解析xml的对象,最早火狐支持,后来都开始支持了。xml = tmp.parseFromString( data , "text/xml");}catch( e ) {xml= undefined;//data必须是完整的xml,不能是html,
}if ( !xml || xml.getElementsByTagName( "parsererror").length ) {jQuery.error("Invalid XML: " +data );}returnxml;},noop:function() {},//Evaluates a script in a global context,全局解析js,/*function test() {jQuery.globalEval( "var newVar = true;" )var newVar1 = true;}test();alert( newVar );alert( newVar1 );function test(){var i = eval;i('var a = 1');eval('var b = 2');window.eval('var c = 3');alert( "s"+a );alert( "s"+b );alert( "s"+c );}test();alert( a );//1alert( b );//buxingalert( c );//3*/globalEval:function( code ) {varscript,indirect=eval;code= jQuery.trim( code );//去前后空格if( code ) {//创建script标签,加文本,加入到head中,删除script标签if ( code.indexOf("use strict") === 1) {script= document.createElement("script");script.text=code;document.head.appendChild( script ).parentNode.removeChild( script );}else{indirect( code );//eval来解析
}}},//把css样式转成js能够接受的,比如js不能接受横杆/*(function(){var a,b=1,c=2;//全局闭包作用域,内部都可以通过闭包链来找到这个外部变量var f = function(o){for(i in o){alert(i+"--"+o[i]());//camelCase--3}}f({camelCase: function( string ) {return b+c;},})})()*///margin-top ->  marginTop  -ms-transform -> msTransform -moz-transform -> MozTransform//rmsPrefix = /^-ms-/, rdashAlpha = /-([\da-z])/gi,    fcamelCase = function( all, letter ) { return letter.toUpperCase(); },camelCase: function( string ) {return string.replace( rmsPrefix, "ms-").replace( rdashAlpha, fcamelCase );},/*replace后面传递函数:rmsPrefix = /^-ms-/;rdashAlpha = /-([\da-z])/gi;fcamelCase = function( all, letter ) { alert(all);//-t,正则匹配到的整体alert(letter);//t,正则里面的子项return letter.toUpperCase(); };camelCase=function( string ) {var d = string.replace( rmsPrefix, "ms-" );//ms-transformvar g = d.replace( rdashAlpha, fcamelCase );//msTransformreturn g;},alert(camelCase('-ms-transform'));*///判断节点的名字是不是指定的名字nodeName: function( elem, name ) {return elem.nodeName && elem.nodeName.toLowerCase() ===name.toLowerCase();},//args is for 内部使用/**var arr = ['a','b','c','d'];var json = { name : 'hello' , age : 20 };$.each(json , function(i,value){//下标  每一个值alert(value);return false;//return false了,只执行一次});*/each:function( obj, callback, args ) {varvalue,i= 0,length= obj.length,//数组有长度,json没有长度,也有可能json里面有一个length属性,isArray = isArraylike( obj );//是不是类数组或者真正数组if ( args ) {//内部使用,平时不传if( isArray ) {for ( ; i < length; i++) {value=callback.apply( obj[ i ], args );if ( value === false) {break;}}}else{for ( i in obj ) {//遍历jsonvalue =callback.apply( obj[ i ], args );if ( value === false) {break;}}}//A special, fast, case for the most common use of each} else{if ( isArray ) {//数组for ( ; i < length; i++ ) {//回调函数value =callback.call( obj[ i ], i, obj[ i ] );if ( value === false ) {//回调函数返回值是false就不循环了break;}}}else {//jsonfor ( i inobj ) {value=callback.call( obj[ i ], i, obj[ i ] );if ( value === false) {break;}}}}returnobj;},trim:function( text ) {return text == null ? "": core_trim.call( text );},//类似于数组转成真正数组/*var s = 123;console.log( $.makeArray( s ) );//[123]console.log( $.makeArray( s , {length:3} ) );//Object {3: 123, length: 4}var str = {1:1,2:2};console.log( $.makeArray( str ) );//[{1:1,2:2}]console.log( $.makeArray( str , {length:3} ) );//{3:{1:1,2:2},length: 4}*/makeArray:function( arr, results ) {var ret = results ||[];if ( arr != null) {/*Object()将基本类型转成对应的对象类型。
console.log(Object(123));//Number {[[PrimitiveValue]]: 123}
console.log(Object('abc'));//String {0: "a", 1: "b", 2: "c", length: 3, [[PrimitiveValue]]: "abc"}
console.log(Object(true));//Boolean {[[PrimitiveValue]]: true}*/if ( isArraylike( Object(arr) ) ) {//'hello'走这里,
jQuery.merge( ret,typeof arr === "string" ?[ arr ] : arr);}else {//123走这里
core_push.call( ret, arr );}}returnret;},/*indexofvar arr = ['a','b','c','d'];alert( $.inArray( 'w' , arr ) ); core_indexOf = [].indexOf,*/inArray:function( elem, arr, i ) {//i是从哪里开始查return arr == null ? -1: core_indexOf.call( arr, elem, i );},/*$.merge(['a','b'],['c','d']);//["a", "b", "c", "d"]$.merge(['a','b'],{0:'c',1:'d'});//["a", "b", "c", "d"]$.merge({0:'a',1:'b',length:2},{0:'c',1:'d'});//{0: "a", 1: "b", 2: "c", 3: "d", length: 4}$.merge({0:'a',1:'b',length:2},['c','d']);// {0: "a", 1: "b", 2: "c", 3: "d", length: 4}*/merge:function( first, second ) {var l =second.length,i=first.length,j= 0;//$.merge( ['a','b'],['c','d'] );if ( typeof l === "number" ) {//json的length不是number,for ( ; j < l; j++) {first[ i++ ] =second[ j ];}}else {//$.merge( ['a','b'],{0:'c',1:'d'} );while ( second[j] !==undefined ) {first[ i++ ] = second[ j++ ];//second的json的属性还必须是0.1.2
}}first.length=i;returnfirst;},/*var arr = [1,2,3,4];arr = $.grep( arr , function( n , i ){//n是每一项,i是下标return n>2;} , true );console.log( arr );//[1,2]*/grep:function( elems, callback, inv ) {varretVal,ret=[],i= 0,length=elems.length;inv= !!inv;//2个!就把undefined转成falsefor ( ; i < length; i++) {retVal= !!callback( elems[ i ], i );//2个!就把不是布尔类型的转成相应的布尔值if ( inv !==retVal ) {ret.push( elems[ i ] );}}returnret;},/*var arr = [1,2,3,4];arr = $.map( arr , function(n){return [n+1];} );console.log( arr );//[2,3,4,5]*/map:function( elems, callback, arg ) {varvalue,i= 0,length=elems.length,isArray=isArraylike( elems ),ret=[];if( isArray ) {for ( ; i < length; i++) {value=callback( elems[ i ], i, arg );if ( value != null) {ret[ ret.length ]= value;//末尾追加
}}}else {//jsonfor ( i inelems ) {value=callback( elems[ i ], i, arg );if ( value != null) {ret[ ret.length ]=value;}}}//ret = [[2],[3],[4],[5]]return core_concat.apply( [], ret );//[2,3,4,5]
},//A global GUID counter for objectsguid: 1,/*function show(n1,n2){alert(n1);alert(n2);alert(this);}show();//window$.proxy(show,document)(3,4);//改变show的this是document,执行,$.proxy(show,document,3)(4);//改变show的this是document,执行,$.proxy(show,document,3)//不执行*/proxy:function( fn, context ) {vartmp, args, proxy;//var obj = {show : function(){}};//$(document).click( $.proxy(obj,'show') );//让obj下面的show指向objif ( typeof context === "string") {context= fn;//context = objfn = tmp;//fn = show//变成了$.proxy(show,obj),统一参数格式
}if ( !jQuery.isFunction( fn ) ) {returnundefined;}//第3个参数3,args = core_slice.call( arguments, 2);proxy= function() {//返回的是函数,后面小括号表示这个函数体执行,return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );//[].slice.call( arguments )把arguments转成真正的数组,arguments是后面的参数
};//后期处理事件proxy.guid = fn.guid = fn.guid || jQuery.guid++;returnproxy;},//内部使用,/*alert( $('#div1').css('width') );$('#div1').css('background','yellow');$('#div1').css(''yellow');$('#div1').css('width','300px');$('#div1').css({ background : 'yellow' , width : '300px' });*/access:function( elems, fn, key, value, chainable, emptyGet, raw ) {//elems=$('#div1'),fn是回调函数,key=background,value=yellow,chainable为真表示设置值为假表示设置值,var i = 0,length=elems.length,bulk= key == null;///没有key就是true,//设置多组值:..css({ background : 'yellow' , width : '300px' })//是object就是json,if ( jQuery.type( key ) === "object") {chainable= true;for ( i inkey ) {jQuery.access( elems, fn, i, key[i],true, emptyGet, raw );}//设置一组值:$('#div1').css('width','300px');} else if ( value !==undefined ) {chainable= true;///不设置就是undefinedif ( !jQuery.isFunction( value ) ) {raw= true;}if ( bulk ) {///没有keyif ( raw ) {///不是函数
fn.call( elems, value );fn= null;}else {///是函数,函数现在不执行,套上一层,里面return时候调用函数bulk =fn;fn= function( elem, key, value ) {returnbulk.call( jQuery( elem ), value );};}}if( fn ) {for ( ; i < length; i++) {fn( elems[i], key, raw?value : value.call( elems[i], i, fn( elems[i], key ) ) );}}}//chainable是真就是设置值,return chainable ?elems ://Getsbulk ?///有没有key值fn.call( elems ) :///有key就调用length ? fn( elems[0], key ) : emptyGet;///又要分长度
},now: Date.now,/*alert( $('#div1').width() );//display:none还是获取到了,利用的是swap方法alert( $('#div1').get(0).offsetWidth );//原生的宽度方法,display:none就获取不到了*/swap:function( elem, options, callback, args ) {varret, name,old= {};//老的样式//Remember the old values, and insert the new onesfor ( name inoptions ) {old[ name ]= elem.style[ name ];//存老的样式elem.style[ name ] = options[ name ];//设置新的样式
}ret= callback.apply( elem, args || [] );//调用函数获取想要的属性值//Revert the old valuesfor ( name inoptions ) {elem.style[ name ]= old[ name ];//样式还原
}returnret;}
});/*$(function(){}) -->  rootjQuery.ready(function(){})  -->  $(document).ready(function(){})  --> $().ready(function(){}) --> jQuery.ready.promise().done( function(){} )  ----------->  addEventListener --> jQuery.ready() --> readyList.resolveWith( document, [ jQuery ] );----------->  readyList.promise( obj ) -->
ready: function( fn ) {jQuery.ready.promise().done( fn );return this;
},*/jQuery.ready.promise= function( obj ) {if ( !readyList ) {//是否加载完,刚开始是false,只走进来一次,
readyList=jQuery.Deferred();if ( document.readyState === "complete" ) {//dom加载完document的属性是完成状态,//Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout( jQuery.ready );}else{/*匿名函数全局作用域,dom加载完成执行的方法completed = function() {document.removeEventListener( "DOMContentLoaded", completed, false );window.removeEventListener( "load", completed, false );jQuery.ready();jQuery.ready() --> readyList.resolveWith( document, [ jQuery ] );};*/document.addEventListener("DOMContentLoaded", completed, false);//A fallback to window.onload, that will always workwindow.addEventListener( "load", completed, false);}}returnreadyList.promise( obj );
};//Populate the class2type map
jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {class2type["[object " + name + "]" ] =name.toLowerCase();
});//是不是数组,特殊数组,带length属性的json
functionisArraylike( obj ) {var length =obj.length,type=jQuery.type( obj );if ( jQuery.isWindow( obj ) ) {//是不是window,下面的判断有可能window也满足,return false;}if ( obj.nodeType === 1 && length ) {//一组元素节点是类数组return true;}//type !== "function"不加这个,那么有length属性的函数就进去了return type === "array" || type !== "function" &&( length=== 0 ||typeof length === "number" && length > 0 && ( length - 1 ) inobj );
}//All jQuery objects should point back to these
rootjQuery = jQuery(document);

转载于:https://www.cnblogs.com/yaowen/p/6931558.html

jQuery源码06-jQuery = function(){};给JQ对象,添加一些方法和属性,extend : JQ的继承方法,jQuery.extend()...相关推荐

  1. Jquery源码分析-整体结构

    最近在学习Jquery的最新的源码,Jquery-3.3.1版本.网上有很多对jquery解析的文章.但是我还是要自己去尝试着看一篇jquery的源码.本系列博客用来记录其中的过程,并同大家分享.本次 ...

  2. 【jQuery源码】整体架构

    jQuery源码可以精简为以下内容: 方框上面的代码根据Jq注释我们可以知道是对AMD规范的支持. jQuery整体上被包裹在一个匿名函数中,这个匿名函数再作为另一个匿名函数的参数被传入,形参fact ...

  3. jQuery源码逐行分析学习01(jQuery的框架结构简化)

    最近在学习jQuery源码,在此,特别做一个分享,把所涉及的内容都记录下来,其中有不妥之处还望大家指出,我会及时改正.望各位大神不吝赐教!同时,这也是我的第一篇前端技术博客,对博客编写还不是很熟悉,美 ...

  4. jQuery源码导航

    jQuery源码框架导航 jQuery的适用面非常的广,用了很久,现在突然想提笔记录一下研读JQuery源码的过程.写文章的时候去jQuery官网查看了一下,最新的jQuery版本是3.4.1,本次解 ...

  5. jQuery源码学习之Callbacks

    jQuery源码学习之Callbacks jQuery的ajax.deferred通过回调实现异步,其实现核心是Callbacks. 使用方法 使用首先要先新建一个实例对象.创建时可以传入参数flag ...

  6. js便签笔记(9)——解读jquery源码时记录的一些知识点

    近来一直利用业余时间在看jquery2.1.1源码,大约看了两千行了.平时看的时候,做了一些笔记,贴出来分享. 1. Array.prototype.slice.call 可以将伪数组转化为真正的数组 ...

  7. jQuery源码学习(1)——addClass

    最近比较闲,寻思着学习下jQuery源码,看了好多博客,很多都讲的比较详细.jQuery虽然只有那么200多K,但内容却比较丰富,对于我这样一个js菜鸟,看起来相当吃力.骨头太大,只能化整为零,从简单 ...

  8. jquery源码学习笔记一:总体结构

    练武不练功,到老一场空.计算机也一样. 计算机的功,就是原理.如果程序员只会使用各种函数,各种框架,而不知其原理,顶多熟练工人而已.知其然,更要知其所以然. jquery我们用得很爽,但它究竟咋实现的 ...

  9. jQuery 源码分析第一篇之入口源码

    目前阅读的是jQuery 1.11.3的源码,有参考nuysoft的资料.原来比较喜欢在自己的Evernote上做学习基类,并没有在网上写技术博客的习惯,现在开始学习JS的开源代码,想跟大家多交流,希 ...

  10. jQuery源码分析-each函数

    本文部分截取自且行且思 jQuery.each方法用于遍历一个数组或对象,并对当前遍历的元素进行处理,在jQuery使用的频率非常大,下面就这个函数做了详细讲解: 复制代码代码 /*! * jQuer ...

最新文章

  1. Apache Artemis —— 非堵塞 Java 嵌入消息服务
  2. 3.4.4 选择重传协议(SR)
  3. [原创]如果软件在网络磁盘中或移动磁盘中运行时需要解决 exception C0000006 异常问题
  4. php函数介绍,PHP函数介绍_PHP教程
  5. Netty详解(五):Netty TCP粘包 拆包
  6. 乐玩插件和大漠插件哪个好_用好这5款Chrome插件,大幅提升你的生产力
  7. C#语法糖 Null 条件运算符 【?.】
  8. 逆水寒服务器维护7.5,逆水寒7.26日维护到什么时候 逆水寒7.26日游戏改动汇总介绍...
  9. LeetCode 1576. 替换所有的问号
  10. python创建一个空的dataframe_python - 创建一个空的Pandas DataFrame,然后填充它?
  11. mac 下 sublime text 运行c++/c 不能使用scanf/cin
  12. 解决多线程编程中大并发数等待唤醒的问题
  13. java基于springboot的ktv点歌管理系统附源码
  14. 【Mysql】Error 1826: Duplicate foreign key constraint 错误
  15. matlab结构力学仿真,MATLAB在结构力学分析中应用.doc
  16. 微信小程序-番外 可视化助手的使用
  17. 爬取获取邮箱内容QQ邮箱or163邮箱
  18. laravel框架excel扩展包maatwebsite-excel升级3.1版本兼容处理
  19. java超级计算器,jdk自带类
  20. 欲罢不能 推荐,刷屏时代如何摆脱行为上瘾

热门文章

  1. LINUX下载编译zlib
  2. 发现新的预言梦种类:预言梦投射
  3. Linux之进程处理方式
  4. centos mysql 安装_Linux下MYSQL5.7详细安装步骤:
  5. 高内聚低耦合_拉锥耦合器最强粘接方案
  6. 项目拉去某个版本的_项目管理的“背后军师”——高层领导
  7. linux 内核 介绍,Linux内核详细介绍
  8. java更新linux_linux下 更新 java版本
  9. office2010 反应慢_office2010打开时间太慢。怎么办?
  10. 安卓3d游戏开发引擎_微信小游戏开发怎么选游戏引擎