日期:2014-05-16  浏览次数:20350 次

javascript 实现简单的弹窗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Transitional//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<title>弹出菜单</title>
<script type="text/javascript">

window.onload = function () {
var menu = document.getElementById("menu");
var links = menu.getElementsByTagName("LI");
var linksArr = new Array();
for (var i=0;i<links.length;i++) {
if (links[i].className == "menuLink") {
linksArr.push(links[i]);
}
}
var childMenus = menu.getElementsByTagName("UL");
for (var i=0;i<childMenus.length;i++) {
childMenus[i].style.display = "none";
}
for (var i=0;i<linksArr.length;i++) {
linksArr[i].menu = childMenus[i];
linksArr[i].onmouseover = show;
linksArr[i].onmouseout = hide;
}
function show() {
this.menu.style.display ="block";
};
function hide() {
this.menu.style.display ="none";
};
};

</script>
<style type="text/css">
ul {
list-style-type:none;
}
#menu {
top: 200px;
left: 200px;
height:200px;
padding:4px;
margin:130px 400px;
}
#menu>li {
width:100px;
height:28px;
border:1px solid #06f;
float:left;
text-align:center;
line-height:28px;
background:white;
margin-right:10px;
cursor:pointer;
position:relative;
}
#menu>li a {
color:navy;
}
#menu>li:hover {
background:blue;
color:white;
}
#menu>li:hover a {
color:white;
}
ul.childMenu {

width:100px;
height:100px;
background:green;
}
</style>
</head>
<body>
<ul id="menu">
<li class="menuLink">
<a href="###">菜单</a>
<ul class="childMenu">
<li><a href="#">子菜单1</a></li>
<li><a href="#">子菜单2</a></li>
<li><a href="#">子菜单3</a></li>
</ul>
</li>
</ul>
</body>
</html>