一点击出现单块闪一下粉色的情况
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.nav {
background-color: aqua;
width: 400px;
height: 60px;
display: flex;
line-height: 60px;
text-align: center;
margin: 100px auto 0;
}
.nav a {
flex: 1;
text-decoration: none;
}
.current {
background-color: pink;
}
.nav_con {
width: 400px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="nav">
<a href="" class="current">123</a>
<a href="">123</a>
<a href="">123</a>
<a href="">123</a>
</div>
<div class="nav_con">
<div>123</div>
<div>123</div>
<div>123</div>
<div>123</div>
</div>
<script>
var nav = document.querySelector('.nav');
var a = nav.querySelectorAll('a');
for (var i = 0;i<a.length;i++) {
a[i].onclick = function(){
for (var i = 0;i<a.length;i++) {
this.className = '';
}
this.className = 'current';
}
}
</script>
</body>
</html>