jQuery 操作css 设置类样式

1、操作css

1.参数只写属性名,则返回属性值

 $(this).css("color");

2.参数是属性名,属性值,逗号分隔,是设置一组样式,属性必须加引号,值如果是数字可以不用跟单位和引号

$(this).css("color","red");
$(this).css("height",400);

3.参数可以是对象形式。属性名和属性值用逗号隔开,属性可以不用加引号

 $(this).css({
            width: 400,
            color: "red"
        })
$(this).css({"color": "white","backgroundColor": "pink"})       //复合属性采取驼峰命名法

2、 设置类样式

1.添加类

$(this).addClass("current");           // 类前面不用加  “ .  ”

2.删除类

$(this).removeClass("current");

3.切换类

 $(this).toggleClass("current");
发布了39 篇原创文章 · 获赞 0 · 访问量 435

猜你喜欢

转载自blog.csdn.net/weixin_43912756/article/details/104235542