jQuery¼¼Êõ

Ê®¸öѸËÙÌáÉýJQueryÐÔÄܵļ¼ÇÉ

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-11-26 17:00 ÎÒÒªÆÀÂÛ( )

Ê®¸öѸËÙÌáÉýJQueryÐÔÄܵļ¼ÇÉ¡£±¾ÎÄÌṩ¼´¿ÌÌáÉýÄãµÄ½Å±¾ÐÔÄܵÄÊ®¸ö²½Öè¡£²»Óõ£ÐÄ£¬Õâ²¢²»ÊÇʲô¸ßÉîµÄ¼¼ÇÉ¡£ÈËÈ˽ԿÉÔËÓã¡ÕâЩ¼¼ÇÉ°üÀ¨£º ʹÓÃ×îа汾 ºÏ²¢

±¾ÎÄÌṩ¼´¿ÌÌáÉýÄãµÄ½Å±¾ÐÔÄܵÄÊ®¸ö²½Öè¡£²»Óõ£ÐÄ£¬Õâ²¢²»ÊÇʲô¸ßÉîµÄ¼¼ÇÉ¡£ÈËÈ˽ԿÉÔËÓã¡ÕâЩ¼¼ÇÉ°üÀ¨£º

ʹÓÃ×îа汾

jQueryÒ»Ö±´¦ÓÚ²»¶ÏµÄ¿ª·¢ºÍ¸Ä½ø¹ý³ÌÖС£ John ºÍËûµÄÍŶӲ»¶ÏÑо¿×ÅÌáÉý³ÌÐòÐÔÄܵÄз½·¨¡£

Ò»µãÌâÍâ»°£¬¼¸¸öÔÂÇ°Ëû»¹·¢²¼ÁËSizzle£¬Ò»¸ö¾Ý˵ÄÜÔÚFirefoxÖаѳÌÐòÐÔÄÜÌáÉý3±¶µÄJSÑ¡ÔñÆ÷¿â¡£

Èç¹ûÄã²»Ïëʱ¿Ì¹Ø×¢ÊÇ·ñÓÐа汾£¬È»ºóÔÙ»¨Ê±¼äÏÂÔØÉÏ´«£¬Google ¾ÍÓÖÄÜ°ïÄãÒ»°ÑÁË¡£ËûÃǵķþÎñÆ÷ÉÏ´æ´¢ÁË´óÁ¿Ajax¿â¹©ÄúÑ¡Ôñ¡£

<!-- ÀûÓÃÒ»¸ö¼òµ¥µÄscript±êÇ©µ÷ÓÃAPI --> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> /* ¼ÓÔØ jQuery v1.3.2 */ google.load ("jquery", "1.3.2", {uncompressed: false}); /* ¼ÓÔØÍê³Éºóµ¯³öÏûÏ¢ */ function onLoad () { alert ("jQuery + Google API!"); } google.setOnLoadCallback (onLoad); </script>

ÁíÒ»¸ö¸üΪ¼òµ¥¿ìËٵķ½·¨ÊÇÖ±½ÓʹÓýű¾Á´½Ó¡£Èç¹ûҪʹÓÃÌض¨°æ±¾µÄjQuery£¬Äã¿ÉÒÔʹÓÃÉÏÃæµÄ·½·¨£»Èç¹ûÏëÖ±½ÓʹÓÃ×îа棬ÏÂÃæÕâ¾ä´úÂë¾Í¹»ÁË£º

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>

Ìض¨°æ±¾µÄ»¹¿ÉÒÔÕâÑù¼ÓÔØ£º

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> ºÏ²¢¡¢×îС»¯½Å±¾

´ó²¿·Öä¯ÀÀÆ÷¶¼²»ÄÜͬʱ´¦Àí¶à¸ö½Å±¾Îļþ£¬ËùÒÔËüÃǶ¼ÊÇÅŶӼÓÔØ¡ª¡ª¼ÓÔØʱ¼äÒ²ÏàÓ¦µØÑÓ³¤ÁË¡£

¿¼Âǵ½ÄãÍøÕ¾µÄÿ¸öÒ³Ã涼»á¼ÓÔØÕâЩ½Å±¾£¬ÄãÓ¦¸Ã¿¼ÂÇ°ÑËüÃǷŵ½µ¥¸öÎļþÖУ¬È»ºóÀûÓÃѹËõ¹¤¾ß£¨±ÈÈç Dean Edwards µÄÕâ¿î£©°ÑËüÃÇ×îС»¯¡£¸üСµÄÎļþÎÞÒɽ«´øÀ´¸ü¿ìµÄ¼ÓÔØËٶȡ£

JavaScriptºÍCSSѹËõµÄÄ¿µÄÊÇÔÚ±£³Ö½Å±¾µÄÖ´ÐÐÐÔÄܵÄͬʱ£¬¼õÉÙÊý¾Ý´«µÝµÄ×Ö½ÚÊý£¨¿ÉÒÔͨ¹ý¼õСԭʼÎļþ£¬Ò²¿ÉÒÔÀûÓÃgzip¡£´ó¶àÊý²úÆ·¼¶µÄÍøÂç·þÎñÆ÷¶¼°Ñgzip×÷ΪHTTPЭÒéµÄÒ»²¿·Ö£©¡£Òý×Ô YUI compressor£¬Ò»¿î jQuery¹Ù·½ÍƼöµÄѹËõ½Å±¾µÄ¹¤¾ß¡£

ÓÃforÌæ´úeach

Ô­Éúº¯Êý×ÜÊDZȸ¨Öú×é¼þ¸ü¿ì¡£

Èç¹ûÓöµ½ÐèÒª±éÀú¶ÔÏóµÄÇé¿ö£¨Èç´ÓÔ¶³Ì½ÓÊÕµÄJSON¶ÔÏ󣩣¬Äã×îºÃÖØдÄãµÄ£¨JSON£©¶ÔÏóΪһ¸öÊý×飬Êý×éµÄÑ­»·´¦ÀíÒªÈÝÒ×Щ¡£

ÀûÓÃFirebug£¬ÎÒÃÇÄܲⶨÿ¸öº¯ÊýµÄÖ´ÐÐʱ¼ä¡£

var array = new Array (); for (var i=0; i<10000; i++) { array[i] = 0; } console.time('native'); //Ô­Éúforº¯Êý var l = array.length; for (var i=0; i<10000; i++) { }

ÉÏÃæµÄ½á¹ûÏÔʾԭÉú´úÂëÖ»Ðè2ºÁÃë¾Í×öµ½µÄÊ£¬ÀûÓÃjQueryµÄeach·½·¨ÐèÒª26ºÁÃë¡£¶øÇÒÕ⻹ֻÊÇÎÒÔÚ±¾»úÉϲâÊÔÒ»¸ö»ù±¾ÉÏɶҲû×öµÄº¯ÊýµÄ½á¹û£¬µ±Óöµ½¸ü¸´ÔÓµÄÇé¿ö£¬ÀýÈçÉèÖÃcssÊôÐÔ»òDOM²Ù×÷ʱ£¬Ê±¼ä²îÒì¿Ï¶¨¸ü´ó¡£

ÓÃIDÌæ´úclassÑ¡ÔñÆ÷

ÀûÓÃIDÑ¡Ôñ¶ÔÏóÒªºÃµÃ¶à£¬ÒòΪÕâʱjQuery»áʹÓÃä¯ÀÀÆ÷µÄÔ­Éúº¯ÊýgetElementByID()À´»ñÈ¡¶ÔÏ󣬲éѯËٶȺܿ졣

Òò´Ë£¬±ÈÆðÀûÓÃÄÇЩ·½±ãµÄcssÑ¡Ôñ¼¼ÇÉ£¬Ê¹ÓøüΪ¸´ÔÓµÄÑ¡ÔñÆ÷Ò²ÊÇÖµµÃµÄ£¨jQueryҲΪÎÒÃÇÌṩÁ˸´ÔÓÑ¡ÔñÆ÷£©¡£ÄãÒ²¿ÉÒÔÊÖ¹¤Êéд×Ô¼ºµÄÑ¡ÔñÆ÷£¨Æäʵ±ÈÄãÏëÏóÖмòµ¥£©£¬»òÕßΪÄãÏëҪѡÔñµÄÔªËØÖ¸¶¨Ò»¸öÓÐIDµÄÈÝÆ÷¡£

//ÏÂÀý´´½¨Ò»¸öÁÐ±í²¢ÇÒÌî³äÌõÄ¿ÄÚÈÝ //È»ºóÿ¸öÌõÄ¿¶¼±»Ñ¡ÔñÒ»´Î //Ê×ÏÈʹÓÃclassÑ¡Ôñ console.time('class'); var list = $('#list'); var items = ' '; for (i=0; i<1000; i++) { items += ' item '; } items += ' '; list.html (items); for (i=0; i<1000; i++) { var s = $('.item' + i); } console.timeEnd('class'); //È»ºóÀûÓÃIDÑ¡Ôñ console.time('id'); var list = $('#list'); var items = ' '; for (i=0; i<1000; i++) { items += ' item '; } items += ' '; list.html (items); for (i=0; i<1000; i++) { var s = $('#item' + i); } console.timeEnd('id');

ÉÏÃæµÄÀý×ӺܺõØ˵Ã÷Á˲»Í¬Ñ¡Ôñ·½Ê½Ö®¼äµÄÏÔÖøÐÔÄܲîÒì¡£Çë¿´ÏÂͼ£¬ÀûÓÃclassÀ´×öÑ¡Ôñ£¬Ê±¼äÎÞÏÞÔö´ó£¬ÉõÖÁ³¬¹ýÁËÎåÃë¡£

¸øÑ¡ÔñÆ÷Ö¸¶¨Ç°ºóÎÄ

jQueryµÄ²Î¿¼ÎĵµÀï˵£º´«µÝ¸øjQuery() ԭʼDOM½ÚµãµÄÇ°ºóÎÄ£¨Èç¹ûûÓж«Î÷±»´«µÝ£¬ÔòÇ°ºóÎÄΪÕû¸öÎĵµ£©¡£Ä¿µÄÊÇÁ¬Í¬Ñ¡ÔñÆ÷Ò»Æð£¬ÊµÏÖ¸üΪ׼ȷµÄ²éѯ¡£

ËùÒÔ£¬Èç¹ûÄãÒ»¶¨ÒªÀûÓÃclassÀ´Ö¸¶¨Ä¿±ê£¬ÖÁÉÙΪѡÔñÆ÷Ö¸¶¨ÉÏÏÂÎÄ£¬ÒÔÃâjQuery·Ñ¾«Á¦È¥±éÀúÕû¸öDOMÎĵµ£º

ÓëÆäÕâÑùд£º

$('.class').css ('color' '#123456');

ΪѡÔñÆ÷¼ÓÉÏÇ°ºóÎıȽϺã¨expression: Ä¿±êÑ¡ÔñÆ÷£»context: Ç°ºóÎÄ£©£º

$(expression, context)

Ò²¾ÍÊÇ˵£º

$('.class', '#class-container').css ('color', '#123456');

ÕâÑù×öÒª¿ìµÃ¶à£¬ÒòΪËü²»ÓñéÀúÕû¸öDOM¡£Ö»ÒªÕÒµ½#class-container¾ÍºÃÁË¡£

½¨Á¢»º´æ

²»Òª·¸²»¶ÏÖØÐÂÑ¡Ôñͬһ¸ö¶«Î÷µÄ´íÎó¡£ÄãÓ¦¸Ã°ÑÄãÒª´¦ÀíµÄÔªËØ»º´æΪһ¸ö±äÁ¿¡£

¸ü²»ÒªÔÚÒ»¸öÑ­»·ÀïÖظ´Ñ¡Ôñͬһ¸öÔªËØ£¡ÕâÑù×öÊ®·ÖÓ°ÏìËٶȣ¡

$('#item').css('color', '#123456'); $('#item').html('hello'); $('#item').css('background-color', '#ffffff'); // ÕâÑùд¸üºÃ $('#item').css('color', '#123456').html('hello').css('background-color', '#ffffff'); // ÉõÖÁÕâÑù var item = $('#item'); item.css('color', '#123456'); item.html('hello'); item.css('background-color', '#ffffff'); // Óöµ½Ñ­»·,ÕâÑù×ö·Ç³£²»ºÃ console.time('no cache'); for (var i=0; i<1000; i++) { $('#list').append(i); } console.timeEnd('no cache'); // ÏÂÃæÕâÑùÒªºÃµÃ¶à console.time('cache'); var item = $('#list'); for (var i=0; i<1000; i++) { item.append (i); } console.timeEnd('cache'); ±ÜÃâDOM²Ù×÷

DOM²Ù×÷Ó¦¸ÃÔ½ÉÙÔ½ºÃ£¬ÒòΪÖîÈçprepend()£¬append()£¬after()µÄ²åÈ붯×÷¶¼ºÜ·Ñʱ¡£ÉÏÃæµÄÀý×ÓÈç¹ûÓÃhtml()»á¸ü¿ì£º

var list = ''; for (var i=0; i<1000; i++) { list += ' '+i+' '; } ('#list').html (list); ±ÜÃâʹÓÃconcat()£¬ÀûÓÃjoin()´¦Àí³¤×Ö´®

ÌýÆðÀ´¿ÉÄÜͦÆæ¹Ö£¬²»¹ýÕâÑù×öÕæµÄÄÜÌáÉýËٶȣ¬ÓÈÆäÊǵ±Á¬½ÓÌر𳤵Ä×Ö´®Ê±¡£ÏȽ¨Á¢Ò»¸öÊý×飬·ÅÈëÄãÏëÒª´®ÁªµÄ¶«Î÷¡£join()·½·¨±È×Ö·û´®µÄconcat()º¯ÊýÒª¿ìµÃ¶à¡£

var array = []; for (var i=0; i< =10000; i++) { array[i] = ' '+i+''; } $('#list').html(array.join (''));

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • Á˽âjQuery¼¼ÇÉÀ´Ìá¸ßÄãµÄ´úÂëÖÊÁ¿(1)

    Á˽âjQuery¼¼ÇÉÀ´Ìá¸ßÄãµÄ´úÂëÖÊÁ¿(1)

    2016-11-19 17:00

  • 20¸öÈÈÃÅjQueryµÄÌáʾºÍ¼¼ÇÉ

    20¸öÈÈÃÅjQueryµÄÌáʾºÍ¼¼ÇÉ

    2016-11-19 16:00

  • JqueryÓ¦Óü¼ÇÉС½á

    JqueryÓ¦Óü¼ÇÉС½á

    2016-11-19 15:03

  • jquery¼¼ÇÉ×ܽáתÔØ

    jquery¼¼ÇÉ×ܽáתÔØ

    2016-11-17 14:08

ÍøÓѵãÆÀ
Å