jQuery之链式编程

使用的思想:隐式迭代、

 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("color", "red");
14                 // 3. 让其余的姐妹元素不变色 
15                 // $(this).siblings().css("color", "");
16                 // 链式编程
17                 $(this).css("color", "red").siblings().css("color", "");
18             });
19         })
20     </script>

 

posted @ 2019-11-29 10:28  遥望那月  阅读(175)  评论(0编辑  收藏  举报