jQuery 使用手册(三)
作者:bea
三: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对象[ <
三: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样式设为red
jQuery提供了以下方法,来操作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对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样式设为red
jQuery提供了以下方法,来操作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>
猜你喜欢
您可能感兴趣的文章:
- jquery 模式对话框终极版实现代码
- 使用JS判断是否数字和小数点组合的数字的两中方法比较(isNaN和逐判断)
- javascript的onchange事件与jQuery的change()方法比较
- 支持ie与FireFox的剪切板操作代码
- javaScript 简单验证代码(用户名,密码,邮箱)
- JS 连锁泡泡 v1.1
- 一个特殊的排序需求的javascript实现代码
- javascript parseInt 大改造
- 网页自动跳转代码收集
- JavaScript中Object和Function的关系小结
- 用Javascript 获取页面元素的位置的代码
- Javascript showModalDialog两个窗体之间传值
- Javascript 两个窗体之间传值实现代码
- Javascript 数组添加 shuffle 方法的实现代码
- Javascript 数组添加一个 indexOf 方法的实现代码
- jQuery 使用手册(七)
- jQuery 使用手册(六)
- jQuery 使用手册(五)
- jQuery 使用手册(四)