使用的方法:click() css() siblings()
1 <button>快速</button> 2 <button>快速</button> 3 <button>快速</button> 4 <button>快速</button> 5 <button>快速</button> 6 <button>快速</button> 7 <button>快速</button> 8 <script> 9 $(function() { 10 // 1. 隱式迭代 給所有的按鈕都綁定了點擊事件 11 $("button").click(function() { 12 // 2. 當前的元素變化背景顏色 13 $(this).css("background", "pink"); 14 // 3. 其余的兄弟去掉背景顏色 隱式迭代 15 $(this).siblings("button").css("background", ""); 16 }); 17 }) 18 </script>