aDiv[j].style.display="none";代码: Uncaught TypeError: Cannot read property 'style' of undefined

window.onload=function()
{
        var oTab=document.getElementById("month_tit");
        var oTac=document.getElementById("month_con");
        var aH3=oTab.getElementsByTagName("li");
        var aDiv=oTac.getElementsByTagName("div");
        for(var i=0;i<aH3.length;i++)
        {
                aH3[i].id=i;
                aH3[i].onmouseover=function()
                {
                        for (var j=0;j<aH3.length;j++)
                        {
                                aH3[j].className="";
                                aDiv[j].style.display="none";
                        }
                        this.className="select";
                        aDiv[this.id].style.display="block";
                }
        }
}
//说这句aDiv[j].style.display="none";代码: Uncaught TypeError: Cannot read property 'style' of undefined
这是为毛啊~~各位大神求救~~~


Hi_给我一个大甜筒
浏览 1886回答 2
2回答

stone310

你的<li>标签数量和<div>标签数量相等吗,按照你的代码,<li>标签数量必须小于等于<div>代码才不会报错,只有等于的时候才能正常显示效果;或者发一下html代码

慕粉3815819

获取id元素的变量你再一次获取它的标签名,所以出错了,参考一下getAttribute()方法
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript