代碼:
<html lang="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>首頁</title>
<script src="jqeury.js"></script>
</head>
<body>
<div style="margin: 200px">
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
<button>快速</button>
</div>
<script>
$(function () {
// 1.隱式迭代 給所有的按鈕都綁定了點擊事件
$("button").click(function () {
// 2.當前元素變化背景顏色
$(this).css("background","pink");
// 3.其餘的兄弟去掉背景顏色
$(this).siblings("button").css("background","");
})
})
</script>
</body>
</html>
效果演示: