<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin:0;
padding: 0;
}
#nav{
width: 100%;
height: 30px;
background-color:yellow;
}
#nav ul li {
float: left;
list-style: none;
margin-left: auto;
border: 2px solid white;
width: 80px;
height: 30px;
text-align: center;
line-height: 30px;
}
.active{
background-color: aqua;
}
</style>
</head>
<body>
<div id="nav">
<ul>
<li>年后
</li>
<li>dad
</li>
<li>沙发
</li>
<li>格式
</li>
<li>大大
</li>
</ul>
</div>
<script type="text/javascript">
var act = document.getElementsByTagName("li");
Array.from(act).forEach(function(sp){
sp.onclick = function()
{
var aa =document.querySelector("li.active")
if(aa)
{
aa.classList.remove("active")
}
this.classList.add("active");
}
})
</script>
</body>
</html>
转载请注明原文地址:https://blackberry.8miu.com/read-16493.html