jquery常用方法之css方法

css ( ) : 给选中的元素添加css样式,或者取css属性样式

添加样式:添加一个或多个属性,添加多个属性用对象的方式写;

    <div class="box">1</div>
    <div class="box">2</div>
<script>
    $(".box:first").css("color","red");
    $(".box:last").css({width:"100",hegiht:"100",color:"#fff",background:"red"});
</script>

效果如下:

取样式:取值是要注意,宽度:取的是带有单位的值,颜色:取的是rgb形式的;直接看下边的代码

console.log( $(".box:first()").css("color") );
console.log( $(".box:last()").css("width") );

打印结果如下:

猜你喜欢

转载自blog.csdn.net/qq_42778001/article/details/90310891