添加类: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>

 

相关文章:

  • 2022-12-23
  • 2021-09-07
  • 2021-07-12
  • 2022-12-23
  • 2021-12-26
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2021-12-30
  • 2021-12-30
  • 2022-12-23
  • 2021-04-19
相关资源
相似解决方案