分页

function page(n,s) {
$("#pageNo2").val(n);
$("#pageSize").val(s);
$("#searchForm").submit();
return false;
}
function jump_to(obj){
var $autopbn = $("#autopbn");
var totalpage = parseInt($autopbn.attr("totalpage"));
var num =parseInt(obj);
if(num<1)num=1;
if(num>totalpage)num=totalpage;
$("#pageIndex").val(num);
page(num);
}
(function (){
var $borspan = $(".borspan");
var $autopbn = $("#autopbn");
var recordnum = parseInt($autopbn.attr("recordnum"));
var curpage = parseInt($autopbn.attr("curpage"));
var totalpage = parseInt($autopbn.attr("totalpage"));
//导航标签的个数,只考虑奇数
var pagenavnum = 5;
//borspan分页导航栏
getPagenav();

function getPageNumberStr(i,pageIndex) {
var $obj = null;
if (i == pageIndex){
$obj = $("<strong>"+pageIndex+"</strong>");
}else{
$obj = $("<a href='javascript:jump_to("+i+");'>"+i+"</a>");
}
return $obj;
}
function getPagenav() {
//上一页,下一页,跳转节点
var $pageinfo = $("<cite>共"+recordnum+"条/"+totalpage+"页&nbsp;</cite>");
var $prev = $("<a href='javascript:jump_to("+(curpage-1)+");'>&nbsp;上一页»&nbsp;</a>");
var $next = $("<a href='javascript:jump_to("+(curpage+1)+");'>&nbsp;下一页»&nbsp;</a>");
var $custompage = $("<input type=\"text\" class=\"page_in\" id=\"destoon_pageno\" value='' onkeydown='if(event.keyCode==13){jump_to(this.value);}' type='text'>" +
"" +
"<input type=\"button\" class=\"page_btn\" value=\"GO\" onclick=\"jump_to($('#destoon_pageno').val());\">");
//上一页标签
if(curpage>1){
$borspan.append($prev);
}
//排除1..34567情况;例如pagenavnum:5,totalpage:6
if(totalpage <= pagenavnum+1){
for (var j = 1; j <= totalpage; j++){
$borspan.append(getPageNumberStr( j, curpage));
}
}else{
//只考虑pagenavnum为奇数的情况,比如为5
var autopagenum = (pagenavnum+1)/2;
//左右两边页码,理论值
var minpage = curpage - (autopagenum - 1);//-1
var maxpage = curpage + (autopagenum - 1);//3
//如果当前项导航块左边>2,并且右边< autopagenum-1
if(minpage > 2 && maxpage < (totalpage-1)){
$borspan.append("<a href='javascript:jump_to(1);'>1..</a>");
for (var j = minpage; j <= maxpage; j++){
$borspan.append(getPageNumberStr( j, curpage));
}
$borspan.append("<a href='javascript:jump_to("+totalpage+");'>.."+totalpage+"</a>");
}else if(minpage < 3){//如果当前项导航块左边<=2,全部为eg:12345 ..n
for (var j = 1; j <= pagenavnum; j++){
$borspan.append(getPageNumberStr( j, curpage));
}
$borspan.append("<a href='javascript:jump_to("+totalpage+");'>.. "+totalpage+"</a>");
}else if(maxpage >= (totalpage-1)){//如果当前项导航块右边>
$borspan.append("<a href='javascript:jump_to(1);'>1 ..</a>");
for (var j =(totalpage-pagenavnum+1); j <= totalpage; j++){
$borspan.append(getPageNumberStr( j, curpage));
}
}
}
//下一页标签
if(curpage<totalpage){
$borspan.append($next);
}

//头部分页信息详情
$borspan.append($pageinfo);
//尾部跳转
$borspan.append($custompage);

}
})()

<div class="borspan" >
<a id="autopbn" href="javascript:;"style="display:none" recordnum="${page.count}" curpage="${page.pageNo}" totalpage="${page.last}"></a>
</div>



posted @ 2018-05-08 10:24  一个写代码的人  阅读(296)  评论(0编辑  收藏  举报