var curPage = 1; //当前页码
var total,pageSize,totalPage; //总记录数,每页显示数,总页数
getData(1);
$("#pagecount").on('click','span a',function(){
var rel = $(this).attr("rel");
if(rel){
getData(rel);
}
});
function getData(page){
$.ajax({
url:ThinkPHP['MODULE']+'/Votesubject/getVotesubjectList',
type:'POST',
data: {'pageNum':page-1},
beforeSend:function(){
},
success:function(json){
// console.log(json);
total = json.total; //总记录数
pageSize = json.pageSize; //每页显示条数
curPage = page; //当前页
totalPage = json.totalPage; //总页数
var ul=$('.theme_body').find('*').remove();
string='';
$.each(json.list,function(index,array){ //遍历json数据列
string+='';
});
$('.theme_body').append(string);
},
complete:function(){ //生成分页条
getPageBar();
},
error:function(){
alert("数据加载失败");
}
});
}
//获取分页条
function getPageBar(){
$("#pagecount").find('*').remove();
//页码大于最大页数
if(curPage>totalPage) curPage=totalPage;
//页码小于1
if(curPage<1) curPage=1;
pageStr = "共"+total+"条"+curPage+"/"+totalPage+"";
//如果是第一页
if(curPage==1){
pageStr += "首页上一页";
}else{
pageStr += "首页上一页";
}
//如果是最后页
if(curPage>=totalPage){
pageStr += "下一页尾页";
}else{
pageStr += "下一页尾页";
}
$("#pagecount").append(pageStr);
}
css样式
.pagecount{
text-align: center;
margin-bottom: 5px;
padding:15px 15px 20px 0;
}
.pagecount span{
display: inline-block;
background: #ddd;
margin:0 0 0 5px;
width:40px;
text-align: center;
padding:2px 8px 2px 8px;
border:1px solid #eee;
color: #666;
}
.pagecount span a{
color:#333;
}
.pagecount span a:hover{
text-decoration: underline;
}
html前端