2024-09-15 20:00:49
var a = document.getElementsByTagName("a");
a.style.color = "#fff";
//关于你贴的图 你是想点击A变色和给Li添加背景吗?建议添加和移除类名;还有你if里面的判断错了吧?nav没看到你定义!莫名奇妙的if判断啊!为什么要判断呢?
var oLi = document.queryselectorAll("#navMenu1 li ");//获取全部LI
var a = document.queryselectorAll("#navMenu1 li a");//全部A
for(var i = 0;i < oLi.length; i++){ // LI
oLi[i].onclick.function(){
oLi.removeClassName = "";
this.addClassName = "li-active";
for(var j = 0; j < a.length; j++){ // A
a.removeClassName = "";
this.addClassName = " a-active";
}
}
2024-09-15 08:05:42