.pages{
margin:0 auto;
margin-top:20px;
}
.pages a{
display:inline-block;
border:1px #ececec solid;
padding:3px 12px;
border-radius:30px;
color:#f9f9f9;
font-size:12px;
background-color:#1a93e9;
}
.pages a:hover,.pages a.click{
background:#ffad00;
border:1px #ffad00 solid;
color:#fff;
}
.pages span{
display:inline-block;
font-size:12px;
padding:0 10px;
}
<div class="pages" id="leftPageIndex">
</div>
function test(size,pageIndex)
{
curcount=data.total;
totalpage=Math.ceil(data.total/10);
}
var totalpage,pagesize,cpage,count,curcount,outstr;
//初始化
cpage = 1;
pagesize = 10;
outstr = "";
function gotopage(target,obj)
{
var year=$("#year").val();
$(obj).addClass("click");
cpage = target; //把页面计数定位到第几页
setpage();
//根据页数调用具体方法
test(pagesize,target);
}
function setpage()
{
if(totalpage<=10){ //总页数小于十页
for (count=1;count<=totalpage;count++)
{ if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
}
if(totalpage>10){ //总页数大于十页
if(parseInt((cpage-1)/10) == 0)
{
for (count=1;count<=10;count++)
{ if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>下一页</a>";
}
else if(parseInt((cpage-1)/10) == parseInt(totalpage/10))
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+(parseInt((cpage-1)/10)*10)+",this)'>上一页</a>";
for (count=parseInt(totalpage/10)*10+1;count<=totalpage;count++)
{ if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
}
else
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+(parseInt((cpage-1)/10)*10)+",this)'>上一页</a>";
for (count=parseInt((cpage-1)/10)*10+1;count<=parseInt((cpage-1)/10)*10+10;count++)
{
if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>下一页</a>";
}
}
$("#leftPageIndex").html(outstr+"<span id=\"rightCount\">第"+cpage+"页|共有"+curcount+"条记录</span>");
outstr = "";
}
margin:0 auto;
margin-top:20px;
}
.pages a{
display:inline-block;
border:1px #ececec solid;
padding:3px 12px;
border-radius:30px;
color:#f9f9f9;
font-size:12px;
background-color:#1a93e9;
}
.pages a:hover,.pages a.click{
background:#ffad00;
border:1px #ffad00 solid;
color:#fff;
}
.pages span{
display:inline-block;
font-size:12px;
padding:0 10px;
}
<div class="pages" id="leftPageIndex">
</div>
function test(size,pageIndex)
{
curcount=data.total;
totalpage=Math.ceil(data.total/10);
}
var totalpage,pagesize,cpage,count,curcount,outstr;
//初始化
cpage = 1;
pagesize = 10;
outstr = "";
function gotopage(target,obj)
{
var year=$("#year").val();
$(obj).addClass("click");
cpage = target; //把页面计数定位到第几页
setpage();
//根据页数调用具体方法
test(pagesize,target);
}
function setpage()
{
if(totalpage<=10){ //总页数小于十页
for (count=1;count<=totalpage;count++)
{ if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
}
if(totalpage>10){ //总页数大于十页
if(parseInt((cpage-1)/10) == 0)
{
for (count=1;count<=10;count++)
{ if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>下一页</a>";
}
else if(parseInt((cpage-1)/10) == parseInt(totalpage/10))
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+(parseInt((cpage-1)/10)*10)+",this)'>上一页</a>";
for (count=parseInt(totalpage/10)*10+1;count<=totalpage;count++)
{ if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
}
else
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+(parseInt((cpage-1)/10)*10)+",this)'>上一页</a>";
for (count=parseInt((cpage-1)/10)*10+1;count<=parseInt((cpage-1)/10)*10+10;count++)
{
if(count!=cpage)
{
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>"+count+"</a>";
}else{
outstr = outstr + "<a href='javascript:void(0)' class='click'>"+count+"</a>";
}
}
outstr = outstr + "<a href='javascript:void(0)' οnclick='gotopage("+count+",this)'>下一页</a>";
}
}
$("#leftPageIndex").html(outstr+"<span id=\"rightCount\">第"+cpage+"页|共有"+curcount+"条记录</span>");
outstr = "";
}