首页 > 其他分享 >a菜单点击标红,其他标黑代码

a菜单点击标红,其他标黑代码

时间:2022-08-17 14:26:04浏览次数:55  
标签:index 菜单 标黑 aList element item let 标红

   <script>
        let aList = document.querySelectorAll('a');
        console.log(aList);
        for (let index = 0; index < aList.length; index++) {
            const element = aList[index];
            element.addEventListener("click", function (e) {
                let txt = e.srcElement.innerText;
                element.style.color = "red";//点击则标红
                for (let index = 0; index < aList.length; index++) {
                    const item = aList[index];
                    if (item.innerText !== txt) {
                        item.style.color = "black";//其他标黑
                    }
                }
            });
        }
    </script>

标签:index,菜单,标黑,aList,element,item,let,标红
From: https://www.cnblogs.com/anjun-xy/p/16595016.html

相关文章

  • win11右键菜单怎么修改
    win11风格→win10风格:打开CMD输入如下,重启电脑即可。regadd"HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"/f/vewin10风......