本题我写的JS有两句报错,是为什么不能这样设置
window.onload=function () {
var oUl1=document.getElementById('ul1');
var ali=oUl1.getElementsByTagName('li');
var odiv=document.getElementById("tab-list");
var adiv=odiv.getElementsByTagName('div');
for(var i=0;i<ali.length;i++){
ali[i].onmouseover=function(){this.className="active";adiv[i].className="";}//报错Uncaught TypeError: Cannot set property 'className' of undefined 为什么必须用先定义 ali[i].index=i; 再使用 adiv[this.index].className="" 才可以
ali[i].onmouseout=function(){this.className="";adiv[i].className="hide"}//报错Uncaught TypeError: Cannot set property 'className' of undefined
}
}