当前位置:首页 > Web开发 > 正文

jQuery之链式编程

2024-03-31 Web开发

使用的思想:隐式迭代、

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>

jQuery之链式编程

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/42421.html