jQuery排他思想

代碼:

<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>

效果演示:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章