window.onload = function (){ var oLi = document.getElementById("tab").getElementsByTagName("li"); var oUl = document.getElementById("content").getElementsByTagName("ul"); for(var i = 0; i < oLi.length; i++) { oLi[i].index = i; oLi[i].onmouseover = function () { for(var n = 0; n < oLi.length; n++) oLi[n].className=""; this.className = "current"; for(var n = 0; n < oUl.length; n++) oUl[n].style.display = "none"; oUl[this.index].style.display = "block" } }}想请问下,oLi[i].index = i; 给遍历的li标签都附上 下标编号的意义是什么,为啥oUl[this.index].style.display = "block"中oUI对象要用[this.index]来表示要改变的是哪个ul标签,为什么不能用循环里定义的i变量??是因为作用域的问题吗?
添加回答
举报
0/150
提交
取消