zoukankan      html  css  js  c++  java
  • jQuery——类的添加与删除

    添加类:addClass

    删除类:removeClass

    判断类是否存在:hasClass

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="jquery-1.11.1.js"></script>
        <style>
            div {
                width: 100px;
                height: 100px;
                border: 1px solid #ccc;
                float: left;
            }
    
            .box1 {
                margin-right: 10px;
            }
    
            .box2 {
                margin-left: 10px;
            }
    
            .show {
                background-color: red;
            }
        </style>
    
        <script src="jquery-1.11.1.js"></script>
        <script>
            $(function () {
                $(".box2").addClass("show");
                $(".box1").removeClass("show");
                console.log($("box1").hasClass("show"));
            });
        </script>
    </head>
    <body>
    <div class="box1"></div>
    <div class="box2"></div>
    </body>
    </html>
  • 相关阅读:
    java 编码问题
    关于时间
    页面
    关于微信
    01-jQuery的介绍
    15-BOM
    14-定时器
    13-JS中的面向对象
    12-关于DOM操作的相关案例
    购物车练习
  • 原文地址:https://www.cnblogs.com/wuqiuxue/p/8032196.html
Copyright © 2011-2022 走看看