日期:2014-05-16 浏览次数:20356 次
<!DOCTYPE HTML>
<html>
<head>
<title> new document </title>
<meta charset="utf-8">
<style>
*{margin:0px; padding:0px;}
#head{width:100%; height:40px; background-color:gray;}
#head nav ul li{display:block;}
.dropdown{width:80px; height:30px; float:left;background-color:black;color:#FFFFFF; margin:10px;}
.dropdown_menu{display:none;}
</style>
</head>
<body>
<header id="head">
<nav id="head_nav">
<ul id="nav_menu">
<li class="dropdown">
<a>Home</a>
</li>
<li class="dropdown">
<a>MENU 1</a>
<ul class="dropdown_menu">
<li>111111</li>
<li>222222</li>
</ul>
</li>
<li class="dropdown">
<a>MENU 1</a>
<ul class="dropdown_menu">
<li>111111</li>
<li>222222</li>
</ul>
</li>
</ul>
</nav>
</header>
<script>
document.body.onload = function(){
var dropdowns = document.getElementsByClassName('dropdown');
for(var i=0;i<dropdowns.length;i++){
d = dropdowns[i];
dropdowns[i].onmouseover = function(){
alert('d='+d.innerHTML);//正常输出innerHTML
alert('dropdowns[i]='+dropdowns[i]);//输出undefined
}
}
}
</script>
</body>
</html>