李晓健
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{
margin: 0;
padding: 0;
}
ul{
margin: 20px;
list-style: none;
}
ul li{
float: left;
margin: 0 5px;
padding: 5px 10px;
color: #ccc;
cursor: pointer;
}
ul li:hover{
color: red;
text-decoration: underline;
}
.active,.active:hover{
background-color: red;
color: #fff;
}
</style>
</head>
<body>
<ul>
<li>首页</li>
<li>上一页</li>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>下一页</li>
<li>尾页</li>
</ul>
<script>
var lis = document.getElementsByTagName('li');
for(var i= 0,len=lis.length;i<len;i++){
lis[i].onclick=function(){
var ac = document.getElementsByClassName('active')[0];
if(ac){
ac.classList.remove('active');
}
this.classList.add('active');
}
}
</script>
</body>
</html>我没考虑兼容性,也是用原生js来写的,你可以参考一下,了解一下思路然后自己再去完整的实现一下