<!DOCTYPE html>
<html>
<head>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width: 100%;
height: 100%;
}
ul{
width: 100%;
height: 50px;
line-height: 50px;
list-style: none;
position: fixed;
top: 0px;
z-index: 1000;
}
ul>a>li{
float: left;
width: 23%;
text-align: center;
}
.content{
position: fixed;
top: 50px;
bottom: 50px;
overflow: auto;
width: 100%;
}
.content div{
float: left;
width: 100%;
height: 100%;
text-align: center;
color: white;
line-height: 500px;
}
.foot{
height: 50px;
position: fixed;
bottom: 0px;
width: 100%;
}
</style>
</head>
<body>
<div class="box">
<header>
<ul>
<a href="#a"><li >1111</li></a>
<a href="#b"><li>2222</li></a>
<a href="#c"><li>3333</li></a>
<a href="#d"><li>4444</li></a>
</ul>
</header>
<div class="content">
<div id="a" style="background: blue;"><h1>11111</h1></div>
<div id="b" style="background: blueviolet;"><h1>22222</h1></div>
<div id="c" style="background: cadetblue;"><h1>33333</h1></div>
<div id="d" style="background: crimson;"><h1>44444</h1></div>
</div>
<div class="foot">
<button onclick="prev()">上一页</button>
<button onclick="next()">下一页</button>
</div>
</div>
</body>
<script>
const Alist = document.querySelectorAll('a>li')
Alist[0].style.background='red';
let index = 0;
for(let i in Alist){
Alist[i].addEventListener('click',function(){
this.style.background='red';
index = parseInt(i)
for(var a =0; a <= Alist.length-1;a++){
if(i != a){
Alist[a].style.background='white';
}
}
})
};
function prev(){
if(index > 0){
index -= 1;
Alist[index].style.background='red';
console.log(Alist[index].parentNode)
Alist[index].parentNode.setAttribute("onclick",'');
Alist[index].parentNode.click()
for(var a =0; a <= Alist.length-1;a++){
if(index != a){
Alist[a].style.background='white';
}
}
}
};
function next(){
if(index < Alist.length-1){
index += 1;
Alist[index].style.background='red';
Alist[index].parentNode.setAttribute("onclick",'');
Alist[index].parentNode.click()
for(var a =0; a <= Alist.length-1;a++){
if(index != a){
Alist[a].style.background='white';
}
};
}
}
</script>
</html>