a菜单点击标红,其他标黑代码
<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>
<a href='#'>首页</a>
<a href='#'>关于</a>