添加多个样式:关键就是有大括号,大括号中的值都是json格式的
$(selector).css({“color”: “red”, “font-size”: “30px” “backgroundcolor”:‘red’});
$(selector).css("width")返回的是该属性的具体值
操作样式通过两种方式,一种是类名,一种是style属性
$(selector).removeClass(); 不指定参数,表示移除被选中元素的所有类
判断该元素下是否包含有该class 属性 可以这样做:$(selector).hasClass(“liItem”);
<style>
div{
width:100px
height:100px
backgroudColor:red
}
.current{
backgroudColor:blue
}
</style>
通过点击button按钮给指定的div更改背景色。所以需要用到
<script>
$(function(){
$("#div").addClass('current')
})
</script>
通过此种方式可以将样式分离出来,更加便于管理和修改。