站长资讯网
最全最丰富的资讯网站

jquery中怎么修改css样式

jquery中修改css样式的方法:1、使用“css("属性名","属性值")”语句修改;2、使用“css({属性名:"属性值",属性名:"属性值"…})”语句修改;3、使用“toggleClass(“类名”)”语句修改。

jquery中怎么修改css样式

本教程操作环境:windows7系统、jquery1.10.0版本、Dell G3电脑。

JQuery修改css样式的方法

css部分:

.div1{       width:100px;       height:100px;       background:#00ff00;       } .div2{        width:100px;        height:100px;        background:#ff0000;       }#Btndiv{          width:100px;          height:100px;          border: 1px solid #ccc;          margin-bottom: 10px;          }

jQuery代码:

<div id="Btndiv" onclick="changeCss()"></div>         <script>             $(document).ready(function (){                 //第一种 //                $("div").css("width","100px"); //                $("div").css("height","100px"); //                $("div").css("background","cyan");                 //第二种 //                $("div").css({ //                    width:"100px",height:"100px",background:"red" //                });                 //第三种                 $("div").addClass("div1");                 $("div").click(function (){ //                    $(this).addClass("div2"); //                  $(this).removeClass("div1");                     $(this).toggleClass("div2");                 });             });     </script>

相关视频教程推荐:jQuery教程(视频)

赞(0)
分享到: 更多 (0)

网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号