jQuery ½Ì³Ì
jQuery Ê×Ò³
jQuery ¼ò½é
jQuery Óï·¨
jQuery Ñ¡ÔñÆ÷
jQuery ʼþ
jQuery Ч¹û
jQuery Òþ²Ø/ÏÔʾ
jQuery µÈëµ³ö
jQuery »¬¶¯
jQuery ¶¯»
jQuery stop()
jQuery Callback
jQuery Chaining
jQuery HTML
jQuery »ñÈ¡
jQuery ÉèÖÃ
jQuery Ìí¼Ó
jQuery ɾ³ý
jQuery CSS Àà
jQuery css()
jQuery ³ß´ç
jQuery ±éÀú
jQuery ±éÀú
jQuery ×æÏÈ
jQuery ºó´ú
jQuery ͬ°û
jQuery ¹ýÂË
jQuery AJAX
jQuery AJAX ¼ò½é
jQuery ¼ÓÔØ
jQuery Get/Post
jQuery ÔÓÏî
jQuery noConflict()
jQuery ʵÀý
jQuery ʵÀý
jQuery ²Î¿¼ÊÖ²á
jQuery ²Î¿¼ÊÖ²á
jQuery Ñ¡ÔñÆ÷
jQuery ʼþ
jQuery Ч¹û
jQuery Îĵµ²Ù×÷
jQuery ÊôÐÔ
jQuery CSS
jQuery Ajax
jQuery ±éÀú
jQuery Êý¾Ý
jQuery DOM ÔªËØ
jQuery ºËÐÄ
jQuery Mobile
jQuery Mobile ʵÀý
Ìá¸ßJQueryÐÔÄܵļ¸¸ö¼¼ÇÉ
jQuery
#ÐÔÄÜ #¼¼ÇÉ2012-08-28 08:54
ÔÚÑ¡Ôñʱ£¬×îºÃÒÔIDÑ¡Ôñ·û×÷Ϊ¿ªÍ·
ÎÒÏëÕâ¸öºÜºÃÀí½â£¬ÒòΪJQueryÄÚ²¿Ê¹ÓÃdocument.getElementByID·½·¨½øÐÐIDÑ¡Ôñ£¬ÕâÖÖ·½·¨±ÈÆäËûËùÓжÔDOMÑ¡ÔñµÄ·½·¨¸ü¿ì£¬ËùÒÔÒÔ$("#")¿ªÍ·ÊÇ×îºÃµÄ,±ÈÈç:
<div id="a"> <div class="b"> <div class="c"> <div class="d"></div> </div> </div> </div> <script type="text/javascript"> $(".b .c .d")//slow one $("#a .b .c .d")//fast one </script>Ìṩ$()µÄÉÏÏÂÎÄ
ÔÚʹÓÃ$()Ñ¡ÔñÒ³ÃæÔªËØʱ£¬ÌṩѡÔñµÄ·¶Î§¿ÉÒÔ¼õÉÙÑ¡ÔñµÄʱ¼ä£¬»»¾ä»°Ëµ£¬ÈÃÑ¡ÔñÆ÷Ö»ÔÚÒ³ÃæµÄһСƬ·¶Î§ÄÚɸѡ¶ø²»ÊÇÕû¸öÒ³Ã浱Ȼ»á¼õÉÙɸѡʱ¼ä£¬Í¨¹ýÔÚ$()º¯ÊýÄÚÌṩµÚ¶þ¸ö²ÎÊý×÷ΪÉÏÏÂÎÄ¿ÉÒÔʵÏÖÕâÒ»µã
<div id="test"> <div class="inner">hi</div> </div> <script type="text/javascript"> alert($(".inner", document.getElementById("test")).text());//increase the speed by provide context alert($(".inner").text());//traverse all the element so that is slower than above </script>µ±È»£¬ÔÚjquery¶¨Òå(»òÕßjsº¯Êý)ʼþÄÚ,¿ÉÒÔͨ¹ýthisÀ´Ö¸´úÉÏÏÂÎÄ:
<div id="test">
<div class="inner">hi</div>
</div>
<script type="text/javascript">
$("#test").click(function() {
var text = $(".inner", this).text(); //this means $("#test")
alert(text);//alert hi
});
</script>
<div id="test">
<div class="inner">hi</div>
</div>
<script type="text/javascript">
alert($("#test .inner").text()); //method 1
alert($("#test").find(".inner").text());//method 2 and it was best one
</script>
µ±È»£¬Èç¹ûÄãÊÇͨ¹ýidÑ¡Ôñ·û£¬Ò²¾ÍÊÇ$("#..")À´Ñ¡Ôñ£¬²»ÐèÒªÌṩÉÏÏÂÎIJÎÊý.Õâ¶ÔËÙ¶ÈûÓÐÓ°Ïì
½«¾³£ÓõÄJQuery°ü×°ºÃµÄÔªËؽøÐб£´æ
ÈçÌ⣬Õâµã±È½ÏÖØÒª£¬ÒòΪʹÓÃ$()¶ÔÒ³ÃæÔªËؽøÐÐÑ¡ÔñÊÇÐèÒªºÄ·Ñʱ¼äµÄ.¶ø±£´æΪ±äÁ¿½øÐÐʹÓÃʱ£¬¿ÉÒÔ±ÜÃâÕâÖÖÀË·Ñ£¬±ÈÈ磺
<ul> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> </ul> <script type="text/javascript"> for (i = 0; i < $("ul li").length; i++) {//very bad,select $("ul li") so many times,waste a lot of time alert($("ul li")[i].innerHTML);//same here,very bad } var $li = $("ul li"); for (i = 0; i < $li.length; i++) {//good one,only selct $("ul li") once alert($li[i].innerHTML); //same here,good } </script>´Ó´úÂë¿ÉÒÔ¿´µ½£¬±ÜÃâ¶à´ÎÖظ´Ñ¡Ôñ¿ÉÒÔÌá¸ßÐÔÄÜ:-)
¾¡Á¿ÉÙÓÃÑ¡Ôñ·û
JQueryµÄÑ¡ÔñÆ÷ÊÇÃæÏòÊý×éµÄ£¬ËùÒÔÔÚÌõ¼þÔÊÐíµÄÇé¿öϾ¡Á¿ÉÙÓÃÑ¡ÔñÆ÷£¬±ÈÈ磺
<div id="Div0"></div> <div id="Div1"></div> <div id="Div2"></div> <script type="text/javascript"> $("#Div0").slideDown("slow"); $("#Div1").slideDown("slow"); $("#Div2").slideDown("slow");//slow $("Div0,Div1,Div2").slideDown("slow");//fast </script>¿ÉÒÔ¿´³ö£¬Ê¹ÓÃÑ¡ÔñÆ÷²¢ÓöººÅ½«±»Ñ¡ÔñµÄÔªËØ·Ö¿ª£¬²¢Ñ¡Ôñ¶à¸öÔªËز»½öÈôúÂë¸ü¼Ó¼ò½à£¬²¢ÇÒͨ¹ý¼õÉÙ´´½¨JQueryµÄʵÀýËùÒÔÔÚÐÔÄÜÉÏÒ²ÉÔʤһ³ï!
ÔÚÑ»·´ÎÊýºÜ¶àʱ±ÜÃâʹÓÃ$().each,¶øʹÓÃforÑ»·
ʹÓÃ$().each·½·¨ÈÃÔÚ½øÐÐÑ»·Ê±£¬»áÈñà³Ì¸ü¼ÓÇáËÉ£¬ÉÙÁ¿µÄÑ»·ÔÚʹÓÃ$().eachʱ¶ÔÐÔÄܵÄÓ°Ïì¿ÉÒÔºöÂÔ²»¼Æ£¬µ«Êǵ±Õâ¸öÊý×ֺܴóµÄʱºò£¬¶ÔÐÔÄܵÄÓ°Ïì±ã¿ªÊ¼±äµÃ¿É¹ÛÁË.
Õâ¸öÊý×Ö£¬ÎÒ²éÁËÏÂ×ÊÁÏ£¬¾Ý˵ÊÇ1000ÒÔÏ¿ÉÒÔʹÓÃ$().each·½·¨£¬¶øÕâ¸öÊý×ÖÈç¹û¼ÌÐøÔö¼Ó£¬ÔòÓ¦¸ÃʹÓÃforÑ»·Óï¾ä¡£¾¡Á¿¼õÉÙ¶ÔDOMµÄ²Ù×÷
¡¡