JqueryÑ¡ÔñÆ÷ $ʵÏÖÔ­Àí

ʱ¼ä£º2016.04.19 ·¢²¼ÈË£ºsherry959

JqueryÑ¡ÔñÆ÷ $ʵÏÖÔ­Àí

Òѽâ¾öÎÊÌâ

¹È¸èsherry959Óû§ÔÚ2016.04.19Ìá½»Á˹ØÓÚ¡°Âí¼×JqueryÑ¡ÔñÆ÷ $ʵÏÖÔ­Àí¡±µÄÌáÎÊ£¬»¶Ó­´ó¼ÒÓ¿Ô¾·¢±í×Ô¼ºµÄ¹Ûµã¡£Ä¿Ç°¹²ÓÐ1¸ö»Ø´ð£¬×îºó¸üÐÂÓÚ2025-02-26T18:10:55¡£Ï£Íû´ó¼ÒÄܹ»°ïÖúËý¡£

ÏêϸÎÊÌâÃèÊö¼°ÒÉÎÊ£ºÆÚ´ýÄúµÄ´ð°¸£¬²»ÖªµÀ˵ʲô,ËÍÄãÒ»¶äСºì»¨°É £¡

Ï£ÍûÒÔϵĻشð£¬Äܹ»°ïÖúÄã¡£

µÚ1¸ö»Ø´ð

Óû§Ãû£ºdepr**edؼÌì  

µ«ÓÉÓÚ¹¤×÷µÄÔ­Òò£¬ºÜ¾Ã²»Ôø×ö¹ýÍøÕ¾ÏîÄ¿ÁË£¬Ò²Ã»ÓÐʱ¼äÈ¥ºÃºÃÑо¿JqueryµÄÔ´Â룬Õâ¸öÒÉÎÊҲһֱûÓеõ½½â¾öÁË£¬½ñÌ죬¿ÕÏÐÖ®Ó࣬´ò¿ªJqueryµÄÔ´Âë¿´¿´£¬²ÅÃ÷ÌìËüʵÏÖµÄÔ­Àí£¬Ô­À´ÔÚ¼ÓÈëjqueryµÄjsÕâ¸öÎļþʱ£¬Êµ¼ÊÉÏÊÇÖ´ÐÐÁËÒ»¸öº¯Êý£¬ÔÚÕâ¸öº¯ÊýÀZ¾­³õʼ»¯ÁË$ºÍJQuery±äÁ¿,ʵÏÖÕâ¸ö¹¦ÄÜÔ´ÂëÈçÏÂ(´úÂëÒÑɾ¼õºÍ¸ü¸Ä£¬²¢²»Ó°Ïì˵Ã÷ʵÏÖÔ­Àí):
¸´ÖÆ´úÂë´úÓ¡µ¥¶Ï¾ÉÊÖÔ¹óÇòδǿÂëÈçÏÂ:
(function(){
var
//Willspeedupreferencestowindo²ÝÁ÷w,andallowsmungingitsname.
window=t±Êºó¸»±£Öܽïhis,
//WillspeedupreferencestoundefÅɵÀÕæÏʵ¼ÔðÑÇÔõµÛ¸»ined,andallowsmungingitsname.
undefined,
//Map³ÉÖ½»Ó»¨overjQueryincaseofoverwrite
_jQuery=windÌ«ÈÔÔõÑÎow.jQuery,
//Mapoverthe$incaseofoverwrite
_$=window.$,
jQueryºÎ¶ÎºñÃÅÊöȼ²¨ºñ¹Ì=window.jQuery=window.$=function(selector,context){
/°åÊØÉù¾°µ±/ThejQueryobjectisactuallyjusttheinitconstructor'enhanced'
returnnewjQuery.fn.init(selector,contÉ绹¾ç²ËÁô¶ûÑøÎ¯ext);
},
//Asim×÷ÑÒÕßÍâÔÓϸÂúplewaytocheckfÎ÷±£ÊÖorh**TMLstringso½ºÔÙÎÊÃñ·¢¹â×ÜÒÑÊ®rIDstrinÂÛ¼ä¸ùΰÈÔÊôgs
//(bothofwhichweoptimiz¶¼ÐÇ´¡À¨ÄÏ·âÁî²ßÆûefor)
quickExprÍ£ÉóƬʳԲ¿´=/^[^<]*(<(.|½«¶Ï°¸Ìâ\s)+>)[^>]*$|^#([\w-]+)$/,
//Isitasimpleselector
isSimple=/^.[^:#\[\.,]*$/;
jQuery.fn=jQuery.prototype={
init:function(selector,context){
//M**esurethataselectionwasprovided
//M**esu¶½¾ÉרÑÝrethataselectionwasprovided
selector=selector||document;
this[0]=selector;
this.length=1;
this.context=selector;
returnthis;
},
show:function(){
alert("***.show");
},
//Startwithanemptyselector
selector:"",
//ThecurrentversionofjQuerybeingused
jquery:"1.3.2"
};
jQuery.fn.init.prototype=jQuery.fn;
})();
functiontest(src){
alert($(src));
$(src).show();

´Ó´úÂëÀïÎÒÃÇ¿ÉÒÔ¿´µ½ÓÐÕâÑùÒ»¸öº¯ÊýÖ´ÐÐÁË(funtion(){})();

varwindow=this;
_jQuery=window.jQuery;
_$=window.$;

Õ⼸¾ä´úÂëÓ¦¸ÃÊÇÉùÃ÷jQueryºÍ$±äÁ¿£¬ÖÁÓÚΪʲôÄÜÕâÑù×ÓÓÃÎÒ»¹Ã»ÅªÃ÷°×£¬µÈ´ý¸ßÈ˽â¾ö£¡£¡

µ«ÎÒÈÏΪÕⲢû¹ØÏµ£¬ÒòΪ×îÖØÒªµÄÊÇÏÂÃæÕâ¶Î´úÂë:

jQuery=window.jQuery=window.$=function(selector,context){
returnnewjQuery.fn.init(selector,context);
};

¿ÉÒÔ¿´³ö´´½¨jQuery.fn.initÕâÑùÒ»¸öº¯Êý·µ»Ø¸ø$£¬ÕâÑùÊÇ¿ÉÒÔʹÓÃ$ʵÀýÁË£¬µ«»**»ÄÜ·ÃÎÊjQuery.fnÀïµÄ·½·¨£¬Òò´ËÐèÒª¼ÓÉϺóÃæÕâ¾ä:

jQuery.fn.init.prototype=jQuery.fn;

ʵÏÖÁËÕâЩ£¬JqueryÖÐµÄÆäËû¹¦ÄܾͺܺÃÀí½âÁË£¬ÎÞ·ÇÊÇÌíprototype»òextendÖеķ½·¨ÁË.