<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题</title>
<link href="style/l.css" style="text/css" rel="stylesheet"/>
<script type="text/javascript" src="js/l.js"></script>
<style type="text/css">
*{ margin:0px; padding:0px;}
body{ font-family:Verdana, Geneva, sans-serif; font-size:14px;}
#nav{ width:600px; height:40px; background-color:#eee; margin:0 auto;}
ul{ list-style:none;}
ul li{ float:left; line-height:40px; text-align:center; width:100px;}
a{ text-decoration:none; color:#000; display:block;}
a:hover{ color:#F00; background-color:#666;}
ul li ul li{ float:none;background-color:#eee; margin:2px 0px;}
ul li ul{ display:none; }
</style>
<script type="text/javascript">
window.onload = function(){
var nav_item = document.getElementsByClassName("nav_item");
for(var i=0;i<nav_item.length;i++){
nav_item[i].onmouseover = function(){
this.getElementsByTagName('ul')[0].style.display = "block";
}
nav_item[i].onmouseout = function(){
this.getElementsByTagName('ul')[0].style.display = "none";
};
}
}
</script>
</head>
<body>
<div id="nav">
<ul>
<li><a href="#">首页</a></li>
<li ><a href="#">符合规范化</a>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">首页</a></li>
<li><a href="#">首页首页首页</a></li>
</ul>
</li>
<li><a href="#">古语我们</a>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">首页</a></li>
<li><a href="#">首页</a></li>
<li><a href="#">首页</a></li>
</ul>
</li>
<li><a href="#">首页</a></li>
<li><a href="#">古语我们</a></li>
</ul>
</div>
</body>
</html>
菜单能正常显示,但是在循环的时候,比如i=0的时候,鼠标放在第一个li标签上时会报错:this.getElementsByTagName('ul')[0] is not defined.怎么解决
相关分类