Ô´ÂëÍø,Ô´ÂëÂÛ̳,Ô´ÂëÖ®¼Ò,ÉÌÒµÔ´Âë,ÓÎÏ·Ô´ÂëÏÂÔØ,discuz²å¼þ,ÆåÅÆÔ´ÂëÏÂÔØ,¾«Æ·Ô´ÂëÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
²é¿´: 73|»Ø¸´: 21

[JavaScript] jQueryʹÓÃÊÖ²áÖ®Èý CSS²Ù×÷

[¸´ÖÆÁ´½Ó]

7Íò

Ö÷Ìâ

861

»ØÌû

32Íò

»ý·Ö

ÂÛ̳ԪÀÏ

Rank: 8Rank: 8

»ý·Ö
329525
·¢±íÓÚ 2007-3-24 00:00:00 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ
´«Í³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£¬ÔòÖ𽥱仯µ½Õý³£
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

1

Ö÷Ìâ

2Íò

»ØÌû

69

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
69
·¢±íÓÚ 2022-10-10 00:07:03 | ÏÔʾȫ²¿Â¥²ã
À´¿´¿´ÔõôÑù

13

Ö÷Ìâ

2Íò

»ØÌû

85

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
85
·¢±íÓÚ 2023-2-10 06:09:13 | ÏÔʾȫ²¿Â¥²ã
Ë¢ÆÁË¢ÆÁË¢ÆÁ

29

Ö÷Ìâ

2Íò

»ØÌû

194

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
194
·¢±íÓÚ 2023-9-2 17:58:50 | ÏÔʾȫ²¿Â¥²ã
ÊÕÏÂÀ´¿´¿´ÔõôÑù

15

Ö÷Ìâ

2Íò

»ØÌû

122

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
122
·¢±íÓÚ 2023-10-28 05:53:01 | ÏÔʾȫ²¿Â¥²ã
ÓÐʲôºÃµÄ·þÎñÆ÷

1

Ö÷Ìâ

2Íò

»ØÌû

207

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
207
·¢±íÓÚ 2024-3-29 11:06:24 | ÏÔʾȫ²¿Â¥²ã
·Ç³£vbcbvcvbvcb

0

Ö÷Ìâ

2Íò

»ØÌû

120

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
120
·¢±íÓÚ 2024-4-26 14:05:39 | ÏÔʾȫ²¿Â¥²ã
66666666666666666666

4

Ö÷Ìâ

1Íò

»ØÌû

60

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
60
·¢±íÓÚ 2024-5-27 05:46:10 | ÏÔʾȫ²¿Â¥²ã
žžžÉúÅÂPSPÅÂ

0

Ö÷Ìâ

1Íò

»ØÌû

0

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
0
·¢±íÓÚ 2024-7-15 02:10:19 | ÏÔʾȫ²¿Â¥²ã
¶ù·É·É΢·çDVDË­vdsvd

0

Ö÷Ìâ

1Íò

»ØÌû

0

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
0
·¢±íÓÚ 2024-7-21 09:32:06 | ÏÔʾȫ²¿Â¥²ã
ÀÏñÄЦÄÉÁË
¸ß¼¶Ä£Ê½
B Color Image Link Quote Code Smilies

±¾°æ»ý·Ö¹æÔò

ÊÖ»ú°æ|СºÚÎÝ|ÍøÕ¾µØͼ|Ô´ÂëÂÛ̳ ( º£Íâ°æ )

GMT+8, 2024-11-21 22:23 , Processed in 0.141053 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí