Jquery使用手册3--css操作 作者:choy
生活随笔
收集整理的這篇文章主要介紹了
Jquery使用手册3--css操作 作者:choy
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
jQuery使用手冊??????????????????????????????????????????????????三:CSS操作
????? 傳統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"
總結
以上是生活随笔為你收集整理的Jquery使用手册3--css操作 作者:choy的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习SQLSERVER2005高可用性数
- 下一篇: (转)40种网站设置技巧