JQuery - $(this) 加 siblings() 的使用

<!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>
posted @ 2020-01-05 18:57  武卡卡  阅读(1705)  评论(0编辑  收藏  举报