<!DOCTYPE html>
<!--思路:先将列表封装在div中,设置为隐藏,当移动到指定位置时则显示,离开列表则继续隐藏-->
<html>
<head>
<title>下拉列表</title>
<meta charset="utf-8">
<style type="text/css">
a{
text-decoration:none ;/*去下划线*/
font-size:14px;
color:CornflowerBlue;
}
div.menu a{
display:block; /*转化为块级元素*/
color:#888;
padding:10px 0 10px 15px;
}
div.menu{
border:1px solid lightgray;/*设置边框的样式*/
width:80px;
}
div#menu1{
margin-left:20px; /*设置外边距定好DIV的位置*/
margin-top: 5px;
}
div#menu2{
margin-left:50px; /*设置外边距定好DIV的位置*/
margin-top: 5px;
}
div#menu3{
margin-left:80px; /*设置外边距定好DIV的位置*/
margin-top: 5px;
}
div.menu a:hover{
background-color:#f1f1f1;
}
</style>
</head>
<body>
<a href="#" id="wq" onmouseover="show1()">武器</a>
<a href="#" id="hj" onmouseover="show2()">护甲</a>
<a href="#" id="yx" onmouseover="show3()">英雄</a>
<div id="menu1" class="menu" onmouseleave="hid1()">
<a href="#">倚天</a>
<a href="#">屠龙</a>
<a href="#">锤子</a>
<a href="#">飞刀</a>
</div>
<div id="menu2" class="menu" onmouseleave="hid2()">
<a href="#">盾牌</a>
<a href="#">铁锅</a>
<a href="#">木盾</a>
<a href="#">铁盾</a>
</div>
<div id="menu3" class="menu" onmouseleave="hid3()">
<a href="#">盖伦</a>
<a href="#">提莫</a>
<a href="#">安妮</a>
<a href="#">死哥</a>
</div>
<script type="text/javascript">
var t1 = document.getElementById("menu1");
t1.style.display = "none";
var t2 = document.getElementById("menu2");
t2.style.display = "none";
var t3 = document.getElementById("menu3");
t3.style.display = "none";
//隐藏
function hid1() {
t1.style.display = "none";
}
//显示
function show1(){
t1.style.display = "block";
t2.style.display = "none";
t3.style.display = "none";
}
//隐藏
function hid2() {
t2.style.display = "none";
}
//显示
function show2(){
t2.style.display = "block";
t1.style.display = "none";
t3.style.display = "none";
}
//隐藏
function hid3() {
t3.style.display = "none";
}
//显示
function show3(){
t1.style.display = "none";
t2.style.display = "none";
t3.style.display = "block";
}
</script>
</body>
</html>