87,920
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link id="link0" type="text/css" rel="stylesheet" href="ifelse.css" />
<script type="text/javascript" src="ifelse.js"></script>
<title>无标题文档</title>
</head>
<body id="body">
<div id="table">
<div id="kuang1">
<p><a href="#" id="btn">下拉菜单</a></p>
<ul id="ul1" >
<li><a href="#" class="a1">下拉选项1</a></li>
<li><a href="#" class="a1">下拉选项2</a></li>
<li><a href="#" class="a1">下拉选项3</a></li>
<li><a href="#" class="a1">下拉选项4</a></li>
<li><a href="#" class="a1">下拉选项5</a></li>
</ul>
</div>
</div>
</body>
</html>
// JavaScript Document
window.onload=function (){
var Btn=document.getElementById('btn');
var Ul=document.getElementById('ul1');
var A=document.getElementsByClassName('a1');
Btn.onclick=function ()
{
if(Ul.style.display=='block'){
Ul.style.display='none';
}
else{
Ul.style.display='block';
}
}
Btn.onmouseover=function ()
{
Btn.style.backgroundColor='rgba(0,90,0,1)';
Btn.style.color='rgba(240,240,240,1)';
}
Btn.onmouseout=function ()
{
Btn.style.backgroundColor='rgba(51,51,51,1)';
Btn.style.color='rgba(255,255,255,1)';
}
var i=0;//循环标记变量
for(i=0;i<=A.length;i++)
{
A[i].onmouseover=function ()
{//创建鼠标移过事件
for(i=0;i<=A.length;i++)
{
A[i].style.backgroundColor='rgba(51,51,51,1)';
}//使全部下拉选项背景色统一
this.style.backgroundColor='rgba(0,90,0,1)';
}//将选中的下拉选项框颜色改变
}
}