|
´«Í³javascript¶ÔcssµÄ²Ù×÷Ï൱·±Ëö£¬±ÈÈç<div id="a" style="background:blue">css</div>È¡ËüµÄbackgroundÓï·¨ÊÇ document.getElementById("a").style.background£¬¶øjQuery¶Ôcss¸ü·½±ãµÄ²Ù×÷£¬$("#a").background()£¬$("#a").background(¡°red¡±) $("#a")µÃµ½jQuery¶ÔÏó[ <div id="a" ¡ /div> ] $("#a").background()½«È¡³ö¸Ã¶ÔÏóµÄbackgroundÑùʽ¡£ $("#a").background(¡°red¡±)½«¸Ã¶ÔÏóµÄbackgroundÑùʽÉèΪredjQueryÌṩÁËÒÔÏ·½·¨£¬À´²Ù×÷css background () background (val) color() color(val) css(name) css(prop) css(key, value) float() float(val) height() height(val) width() width(val) left() left(val) overflow() overflow(val) position() position(val) top() top(val)
ÕâÀïÐèÒª½²½âÒ»ÏÂcss(name) css(prop) css(key, value)£¬ÆäËûµÄ¿´Ãû×Ö¶¼ÖªµÀʲô×÷ÓÃÁË£¡
<div id="a" style="background:blue; color:red">css</div><P id="b">test</P> css(name) »ñÈ¡ÑùʽÃûΪnameµÄÑùʽ $("#a").css("color") ½«µÃµ½ÑùʽÖÐcolorÖµred£¬("#a").css("background ")½«µÃµ½blue
css(prop) propÊÇÒ»¸öhash¶ÔÏó£¬ÓÃÓÚÉèÖôóÁ¿µÄcssÑùʽ $("#b").css({ color: "red", background: "blue" }); ×îÖÕЧ¹ûÊÇ<p id="b" style="background:blue; color:red">test</p>,{ color: "red", background: "blue" }£¬hash¶ÔÏó£¬colorΪkey£¬"red"Ϊvalue£¬
css(key, value) ÓÃÓÚÉèÖÃÒ»¸öµ¥¶ÀµÃcssÑùʽ $("#b").css("color","red");×îÖÕЧ¹ûÊÇ<p id="b" style="color:red">test</p>
ËÄ£ºJavaScript´¦Àí
$.browser() ÅжÏä¯ÀÀÆ÷ÀàÐÍ£¬·µ»ØboolenÖµ
$(function(){ if($.browser.msie) { alert("ÕâÊÇÒ»¸öIEä¯ÀÀÆ÷");} else if($.browser.opera) { alert("ÕâÊÇÒ»¸öoperaä¯ÀÀÆ÷");} })µ±Ò³ÃæÔØÈëʽÅжÏä¯ÀÀÆ÷ÀàÐÍ£¬¿ÉÅжϵÄÀàÐÍÓÐmsie¡¢mozilla¡¢opera¡¢safari
$.each(obj, fn) objΪ¶ÔÏó»òÊý×飬fnΪÔÚobjÉÏÒÀ´ÎÖ´Ðеĺ¯Êý£¬×¢ÒâÇø·Ö$().each()
$.each( [0,1,2], function(i){ alert( "Item #" + i + ": " + this ); }); ·Ö±ð½«0£¬1£¬2Ϊ²ÎÊý£¬´«Èëµ½function(i)ÖÐ
$.each({ name: "John", lang: "JS" }, function(i){ alert( "Name: " + i + ", Value: " + this ); { name: "John", lang: "JS" }Ϊһ¸öhash¶ÔÏó£¬ÒÀ´Î½«hashÖÐÿ×é¶ÔÏó´«Èëµ½º¯ÊýÖÐ
$.extend(obj, prop) Óõڶþ¸ö¶ÔÏóÀ©Õ¹µÚÒ»¸ö¶ÔÏó
var settings = { validate: false, limit: 5, name: "foo" }; var options = { validate: true, name: "bar" }; $.extend(settings, options);Ö´Ðкósettings¶ÔÏóΪ{ validate: true, limit: 5, name: "bar" } ¿ÉÒÔÓÃÏÂÃ溯ÊýÀ´²âÊÔ
$(function(){ var settings = { validate: false, limit: 5, name: "foo" }; var options = { validate: true, name: "bar" }; $.extend(settings, options); $.each(settings, function(i){ alert( i + "=" + this ); }); }) $.grep(array,fn) ͨ¹ýº¯ÊýfnÀ´¹ýÂËarray£¬½«arrayÖеÄÔªËØÒÀ´Î´«¸øfn£¬fn±ØÐë·µ»ØÒ»¸öboolen£¬Èçfn·µ»Øtrue£¬½«±»¹ýÂË
$(function(){ var arr= $.grep( [0,1,2,3,4], function(i){ return i > 2; }); $.each(arr, function(i){ alert(i); }); })ÎÒÃÇ¿ÉÒÔ¿´´ýÖ´ÐÐ$.grepºóÊý×é[0,1,2,3,4]±ä³É[0£¬1]
$.merge(first, second) Á½¸ö²ÎÊý¶¼ÊÇÊý×飬ÅųöµÚ¶þ¸öÊý×éÖÐÓëµÚÒ»¸öÏàͬµÄ£¬ÔÙ½«Á½¸öÊý×éºÏ²¢
$(function(){ var arr = $.merge( [0,1,2], [2,3,4] ) $.each(arr, function(i){ alert(i); }); })¿ÉÒÔ¿´³öarrµÄ½á¹ûΪ[0,1,2,3,4]
$.trim(str) ÒƳö×Ö·û´®Á½¶ËµÄ¿Õ¸ñ $.trim(" hello, how are you? ")µÄ½á¹ûÊÇ"hello, how are you?"
Î壺¶¯Ì¬Ð§¹û
ÔÚ½«Õⲿ·Ö֮ǰÎÒÃÇÏÈ¿´¸öÀý×Ó£¬ÏàÐÅ×öÍøÒ³µÄÅóÓѶ¼Óöµ½n¼¶²Ëµ¥µÄÇé¾°£¬µ«µã»÷ij²Ëµ¥°´Å¥Ê±£¬Èç¹ûËüµÄ×Ӳ˵¥ÊÇÏÔʾµÄ£¬ÔòÒþ²Ø×Ӳ˵¥£¬Èç¹û×Ӳ˵¥Òþ²Ø£¬ÔòÏÔʾ³öÀ´£¬´«Í³µÄjavascript×ö·¨ÊÇÏÈÓÃgetElementByIdÈ¡³ö×Ӳ˵¥ËùÔÚÈÝÆ÷µÄid£¬ÔÚÅжϸÃÈÝÆ÷µÄstyle.displayÊÇ·ñµÈÓÚnone£¬Èç¹ûµÈÓÚÔòÉèΪblock,Èç¹û²»µÈÓÚÕâÉèΪnone£¬Èç¹ûÔÚ½«Ð§¹ûÉèÖø´ÔÓÒ»µã£¬µ±µã»÷°´Å¥Ê±£¬²»ÊǺöÈ»Òþ²ØºÍÏÔʾ×Ӳ˵¥£¬¶øÊǸ߶Èƽ»¬µÄת±ä£¬Õâʱ¾ÍҪͨ¹ýsetTimeoutÀ´ÉèÖÃ×Ӳ˵¥µÄheightÁË£¬ÔÙ¸´ÔÓÒ»µã͸Ã÷¶ÈҲƽ»¬µÄÏûʧºÍÏÔÏÖ£¬ÕâʱÏÔÏÖÏÂÀ´ÐèÒª±àдºÜ¶à´úÂ룬Èç¹ûjs»ù´¡²»ºÃµÄÅóÓÑ¿ÉÄÜÖ»ÄÜ´Ó±ðÈËдºÃµÄ´úÂëÄùýÀ´ÐÞ¸ÄÁË£¡jQueryʵÏÖÉÏÃæЧ¹ûÖ»ÐèÒª1¾ä»°¾ÍÐУ¬$("#a").toggle("slow"),,ѧÍêjQueryºó»¹ÐèÒª³Ï®Ð޸ıðÈ˵ĴúÂëÂð£¿ÏÂÃæÎÒÃÇÖð¸ö½éÉÜjQueryÓÃÓÚЧ¹û´¦ÀíµÄ·½·¨¡£
hide() Òþ²ØÆ¥Åä¶ÔÏó
<p id="a">Hello Again</p><a href="#" onClick=' ("#a").hide()'>jQuery</a>µ±µã»÷Á¬½Óʱ,idΪaµÄ¶ÔÏóµÄdisplay±äΪnone¡£
show() ÏÔʾƥÅä¶ÔÏó
hide(speed) ÒÔÒ»¶¨µÄËÙ¶ÈÒþ²ØÆ¥Åä¶ÔÏó£¬Æä´óС£¨³¤¿í£©ºÍ͸Ã÷¶È¶¼Ö𽥱仯µ½0£¬speedÓÐ3¼¶("slow", "normal", "fast")£¬Ò²¿ÉÒÔÊÇ×Ô¶¨ÒåµÄËٶȡ£
show(speed) ÒÔÒ»¶¨µÄËÙ¶ÈÏÔʾƥÅä¶ÔÏó£¬Æä´óС£¨³¤¿í£©ºÍ͸Ã÷¶È¶¼ÓÉ0Ö𽥱仯µ½Õý³£
hide(speed, callback) show(speed, callback) µ±ÏÔʾºÍÒþ²Ø±ä»¯½áÊøºóÖ´Ðк¯Êýcallback
toggle() toggle(speed) Èç¹ûµ±Ç°Æ¥Åä¶ÔÏóÒþ²Ø£¬ÔòÏÔʾËûÃÇ£¬Èç¹ûµ±Ç°ÊÇÏÔʾµÄ£¬¾ÍÒþ²Ø£¬toggle(speed),Æä´óС£¨³¤¿í£©ºÍ͸Ã÷¶È¶¼ËæÖ®Ö𽥱仯¡£
<img src="1.jpg" style="width:150px"/> <a href="#" onClick='$("img").toggle("slow")'>jQuery</a> fadeIn(speeds) fadeOut(speeds) ¸ù¾ÝËٶȵ÷Õû͸Ã÷¶ÈÀ´ÏÔʾ»òÒþ²ØÆ¥Åä¶ÔÏó£¬×¢ÒâÓбðÓÚhide(speed)ºÍshow(speed)£¬fadeInºÍfadeOut¶¼Ö»µ÷Õû͸Ã÷¶È£¬²»µ÷Õû´óС
<img src="1.jpg" style="display:none"/><a href="#" onClick='$("img ").fadeIn("slow")'> jQuery </a>µã»÷Á¬½Óºó¿ÉÒÔ¿´µ½Í¼Æ¬Öð½¥ÏÔʾ¡£
fadeIn(speed, callback) fadeOut(speed, callback) callbackΪº¯Êý£¬ÏÈͨ¹ýµ÷Õû͸Ã÷¶ÈÀ´ÏÔʾ»òÒþ²ØÆ¥Åä¶ÔÏ󣬵±µ÷Õû½áÊøºóÖ´ÐÐcallbackº¯Êý
<img src="1.jpg"/> <a href="#" onClick='$("img ").fadeIn("slow",function(){ alert("Animation Done."); })'> jQuery </a>µã»÷Á¬½Óºó¿ÉÒÔ¿´µ½Í¼Æ¬Öð½¥ÏÔʾ,ÏÔʾÍêÈ«ºóµ¯³ö¶Ô»°¿ò
fadeTo(speed, opacity, callback) ½«Æ¥Åä¶ÔÏóÒÔspeedËٶȵ÷Õûµ¹Í¸Ã÷¶Èopacity£¬È»ºóÖ´Ðк¯Êýcallback¡£OpacityΪ×îÖÕÏÔʾµÄ͸Ã÷¶È(0-1).
<img src="1.jpg"/><br> <a href="#" onClick='$("img ").fadeTo("slow",0.55,function(){ alert("Animation Done."); })'> jQuery </a>´ó¼Ò¿ÉÒÔ¿´Ò»ÏÂ×Ô¼º¿´¿´Ð§¹û£¬Èç¹û²»ÓÃjQuery£¬±àдÔʼjavascript½Å±¾¿ÉÄܺܶà´úÂ룡
slideDown(speeds) ½«Æ¥Åä¶ÔÏóµÄ¸ß¶ÈÓÉ0ÒÔÖ¸¶¨ËÙÂÊƽ»¬µÄ±ä»¯µ½Õý³££¡
<img src="1.jpg" style="display:none"/> <a href="#" onClick='$("img ").slideDown("slow")'>jQuery</a> slideDown(speeds,callback) ½«Æ¥Åä¶ÔÏóµÄ¸ß¶ÈÓÉ0±ä»¯µ½Õý³££¡±ä»¯½áÊøºóÖ´Ðк¯Êýcallback
slideUp("slow") slideUp(speed, callback) Æ¥Åä¶ÔÏóµÄ¸ß¶ÈÓÉÕý³£±ä»¯µ½0
slideToggle("slow") Èç¹ûÆ¥Åä¶ÔÏóµÄ¸ß¶ÈÕý³£ÔòÖ𽥱仯µ½0£¬ÈôΪ0£¬ÔòÖ𽥱仯µ½Õý³£ |
|