jQuery class属性值... 登录

jQuery class属性值操作

上一章节介绍了一下内容:

$().attr(‘class’,值);

$().attr(‘class’);

$().removeAttr(‘class’);  //删除class的属性

 本节补充如下内容:

$().addClass(值);    //给class属性追加信息值

$().removeClass(值); //删除class属性中的某个信息值

$().toggleClass(值); //开关效果,有就删除,没有就添加

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
            function f1(){
                $("div").addClass('s2');
            }
            function f2(){
                $("div").removeClass('s2');
            }
            function f3(){
                $("div").toggleClass('s2')
            }
        </script>
        <style type="text/css">
            .s2{
                width:250px;
                height:25px;
                background: yellow;
            }
        </style>
    </head>
    <body>
        <div class="s1">欢迎大家学习我们的jQuery课程</div>
        <input type="button" value="设置" onclick="f1()" />
        <input type="button" value="删除class的属性值" onclick="f2()" />
        <input type="button" value="开关class属性值的操作" onclick="f3()" />
    </body>
</html>
下一节
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ $("div").addClass('s2'); } function f2(){ $("div").removeClass('s2'); } function f3(){ $("div").toggleClass('s2') } </script> <style type="text/css"> .s2{ width:250px; height:25px; background: yellow; } </style> </head> <body> <div class="s1">欢迎大家学习我们的jQuery课程</div> <input type="button" value="设置" onclick="f1()" /> <input type="button" value="删除class的属性值" onclick="f2()" /> <input type="button" value="开关class属性值的操作" onclick="f3()" /> </body> </html>
提交 重置代码
章节 评论 笔记 课件
  • 取消 回复 发送
  • 取消 发布笔记 发送