在ie11下调试,报出:0x800a138f - JavaScript 运行时错误: 无法获取未定义或 null 引用的属性<script language="javascript"> function initializeMenu(menuName) { var menu= document.getElementsByName(menuName); var k,i,len,tablelen; for ( k=0,tablelen=menu.length; k <tablelen; k++) { var actuator=menu[k]; actuator.onclick = function() { var display = this.nextSibling.nextSibling.style.display; if (display == "none") this.nextSibling.nextSibling.style.display = "block"; else this.nextSibling.nextSibling.style.display = "none"; return false;} } } function showcategory(menuID) { var menu=document.getElementById(menuID); //menu.className=""; while (menu.parentElement.id!="MenuRoot") { if (menu.tagName=="UL" && menu.style.display=='none') { menu.style.display="block"; //menu.className=""; } menu=menu.parentElement; } } window.onload = function() { initializeMenu("menuname"); } </script> <div id="MenuRoot"> <ul> <ul> <li><a href="#" name="menuname" id="1">第一级菜单</a> <ul style="display:none"> <li><a href="#" >第二级菜单3</a></li> <li><a href="#">第二级菜单4</a></li> <li><a href="#">第二级菜单5</a></li> </ul> </li> <li><a href="" name="menuname" title="" id="2">Flashlights</a> <ul style="display:none"> <li><a href="">Rechargeable Flashlights</a></li> <li><a href="" >LED Flashlights & Sets</a></li> </ul> </li> </ul> </ul> </div> <script>showcategory("2");</script>
添加回答
举报
0/150
提交
取消