選項(xiàng)卡切換功能實(shí)現(xiàn),關(guān)于循環(huán)執(zhí)行順序的影響
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的長(zhǎng)度都是3,這里把
?for(var i = 0; i < y.length; i++) { y[i].className = ""; }
????????和
for(var j = 0; j < z.length; j++) {z[j].className = "hide"; }
循環(huán)合并,怎么就不行了?
2019-08-15
這樣嗎?可以運(yùn)行?