代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="./jquery-3.6.0.js"></script>
<style>
button{
width: 200px;
height: 200px;
}
</style>
<script>
$(function () {
/* $("button").click(function(){
$(this).css("background","aqua");
$(this).siblings().css("background","")
}) */
$("button").click(function(){
$("button").css("background","")
$(this).css("background","aqua");
})
});
</script>
</head>
<body>
<button></button>
<button></button>
<button></button>
<button></button>
</body>
</html>
注意:注释里面为另一种方法