JS当前菜单高亮显示,怎么弄啊1
发布网友
发布时间:2023-09-15 02:43
我来回答
共1个回答
热心网友
时间:2024-03-08 18:22
写了,你看看,觉得可以欢迎采纳
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<style>
.navigation
{
width:200px;
height:30px;
background: #ccc;
border:1px solid #ccc;
padding: 0;
margin: 50px;
}
.navigation ul
{
width:200px;
height:30px;
margin: 0;
padding: 0;
list-style-type: none;
}
.navigation ul li
{
width:80px;
height:30px;
margin: 0;
padding: 0;
float: left;
text-align: center;
line-height: 30px;
}
.navigation ul li a
{
text-decoration: none;
margin: 0;
}
.navigation ul li.active
{
background: #f90;
}
</style>
<script>
window.onload=function()
{
var aLi=document.getElementsByTagName('li');
for(var i=0;i<aLi.length;i++)
{
//鼠标移入设置class为active
aLi[i].onmouseover=function()
{
this.className='active';
}
//鼠标移出去掉class
aLi[i].onmouseout=function()
{
this.className='';
}
}
}
</script>
</head>
<body>
<div class="navigation" >
<ul>
<li>
<a href="/">首页</a>
</li>
<li>
<a href="/jianshenfangfa/">健身方法</a>
</li>
</ul>
</div>
</body>
</html>