function getli(index,count){ //index 是当前页数 count是总页数
var li="<li><a href='#' aria-label='Previous' onclick='toup()'>
<span aria-hidden='true'>«</span></a></li>";
if(count<6){
for (var i=0;i<count;i++){
li+="<li><a href='#' >"+(i+1)+"</a></li>";
}
}else{
var page=0;
if(index-2<1){
if(index-1<1){
page=index;
}else{
page=index-1;
}
}else{
page=index-2;
}
if(index+2>count){
if(index+1>count){
count=index;
}else{
count=index+1;
}
}else{
if(index<3){
count=5
}else{
count=index+2;
}
}
if(count-page+1<5){
var i=5-(count-page)-1;
page=page-i;
}
for (var i=0;page<=count;page++){
li+="<li><a href='#'>"+page+"</a></li>";
}
}
li+="<li><a href='#' aria-label='Next' onclick='tonext()'><span aria-hidden='true'>»</span></a></li>";
$("#listPage").html(li);
}
效果图