jQuery css类
$(selecor).css(name)
css()方法返回或设置匹配元素的一个或多个样式属性。
设置<p>元素的颜色:
$(".button").click(function(){
$("p").css("color","red");
});使用函数来设置css属性
$(selector).css(name,function(index,value)) //此函数返回要设置的属性值。接受两个参数,index 为元素在对象集合中的索引位置,value 是原先的属性值。
例如将所有段落的颜色设为黄色
$("button").click(function(){
$("p").css("color",function(){return "yellow";});
});逐渐增加div的宽度
$("div").click(function() {
$(this).css(
"width", function(index, value) {return parseFloat(value) * 1.2;}
);
});设置多个css属性
$(selector).css({property:value, property:value, ...})例如
$("button").click(function(){
$("p").css({
"color":"white",
"background-color":"#98bf21",
"font-family":"Arial",
"font-size":"20px",
"padding":"5px"
});
});
});jQuery width(),height()
width() 方法设置或返回元素的宽度(不包括内边距、边框或外边距)。相关推荐
qiupu 2020-11-04
jiedinghui 2020-10-25
Ladyseven 2020-10-22
hellowzm 2020-10-12
zuncle 2020-09-28
Ladyseven 2020-09-11
jiedinghui 2020-09-07
xiaohuli 2020-09-02
葉無聞 2020-09-01
impress 2020-08-26
ThikHome 2020-08-24
nicepainkiller 2020-08-20
hellowzm 2020-08-18