慕函数2570892
2019-08-13 17:39
window.onload =function(){
var x = document.getElementById("ul1");
var y = x.getElementsByTagName("li");
var z = document.getElementById("tab-list").getElementsByTagName("div");
for(var i=0;i<y.length;i++){
y[i].index = i;
y[i].onmouseover = function(){
for(var i = 0; i < y.length; i++) { y[i].className = ""; }
this.className = "active";
for(var j = 0; j < z.length; j++) {z[j].className = "hide"; }
z[this.index].className = "show";
}
}
}
y和z的长度都是3,这里把
for(var i = 0; i < y.length; i++) { y[i].className = ""; }
和
for(var j = 0; j < z.length; j++) {z[j].className = "hide"; }
循环合并,怎么就不行了?
这样吗?可以运行?
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题