<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin:0px;
padding: 0px;
}
#one{
}
#one li{
width: 50px;
height: 30px;
border:1px solid black;
text-align: center;
list-style: none;
float: left;
line-height: 30px;
}
#two li{
width: 50px;
height: 30px;
border:1px solid black;
list-style: none;
line-height: 30px;
text-align: center;
/*clear: both;*/
}
#two{
position: absolute;
top: 30px;
}
.select{
background: rgb(0,200,0);
}
</style>
</head>
<body>
<ul id="one"></ul>
<ul id="two"></ul>
<script type="text/javascript">
var arr1=["标题一","标题二"];
var arr2=[["a","b","c","d"],["one","two","three","four"]];
var one=document.getElementById('one');
var two=document.getElementById('two');
for(var n=0;n<arr1.length;n++){
var li=document.createElement("li");
li.innerHTML=arr1[n];
one.appendChild(li);
}
var li=document.getElementsByTagName('li');
for(var n=0;n<li.length;n++){
li[n].value=n;
li[n].onmouseover=function(){
for(var n=0;n<li.length;n++){
li[n].className="";
}
li[this.value].className="select";
var str="";
for(var n=0;n<arr2[this.value].length;n++){
str=str+"<li>"+arr2[this.value][n]+"</li>";
}
two.innerHTML=str;
two.style.left=(this.value*52)+"px";
}
}
one.onmouseover=function(){
two.style.display="block";
}
one.onmouseout=function(){
two.style.display="none";
}
two.onmouseover=function(){
two.style.display="block";
}
two.onmouseout=function(){
two.style.display="none";
}
</script>
</body>
</html>
JavaScript——下拉菜单实现
最新推荐文章于 2024-04-14 17:05:03 发布