<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>this的使用</title>
    <script src="jquery-3.4.1.min.js"></script>
</head>
<body>
    <button>aaa</button>
    <button>bbb</button>
    <button>ccc</button>

 

    <script>
        $(()=>{
             $("button").click(function(){
                $(this).addClass("test")//为当前元素增加test类
                $(this).siblings().removeClass("test")//获取元素的兄弟元素,并去掉他们的test类   (siblings() 方法返回被选元素的所有同级元素。)
            });
        })
    </script>
</body>
</html>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-07-30
  • 2021-05-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
相关资源
相似解决方案