/** * @description: 分页 * @author: ishang_pan * @update: ishang_pan (2019-08-29 10:57) */ $(function () { var current = parseInt($("pagination").attr("currentpage")); var count = parseInt($("pagination").attr("pagecount")); var total = parseInt($("pagination").attr("total")); if(count < 1){ count = 1; } if(current > count){ location.href = '/404.html'; } if(count > 1){ //$("#pagination").append(''); $("#pagination").append(''); if(current > 1){ $("#paging").append('
  • 首页
  • 上页
  • '); }else{ $("#paging").append('
  • 首页
  • 上页
  • '); } if(count <= 5 || (count > 5 && current < 3)) { for (var i = 1; i <= count && i <= 5; i++) { if (current == i) { $("#paging").append('
  • ' + i + '
  • '); } else { $("#paging").append('
  • ' + i + '
  • '); } } }else if(count > 5 && (count-current) < 3){ for (var i = count-4; i <= count; i++) { if (current == i) { $("#paging").append('
  • ' + i + '
  • '); } else { $("#paging").append('
  • ' + i + '
  • '); } } }else if(count > 5 && current >= 3 && (count-current) >= 3){ $("#paging").append('
  • '+(current-2)+'
  • ' +'
  • '+(current-1)+'
  • ' +'
  • '+current+'
  • ' +'
  • '+(current-0+1)+'
  • ' +'
  • '+(current-0+2)+'
  • '); } if(current < count){ $("#paging").append('
  • 下页
  • 末页
  • '); }else{ $("#paging").append('
  • 下页
  • 末页
  • '); } $("#paging").append('
  • 共'+count+'页 到第
  • ' +'
  • 确定
  • '); $("#paging").append('
  • 共' + total + '条
  • '); } }); //直达页面input,按回车键即可跳转 function gopage(page,totalpage) { var url = window.location.href; if (event.keyCode == 13) { if (Math.abs(page) > totalpage) page = totalpage; if(url.indexOf("page_") > -1) { url = url.replace(/page_[1-9][0-9]*/,"page_"+page); }else if (url.indexOf("page=") == -1) { if (url.indexOf("?") == -1) { url = url + "?page=" + page; }else{ url = url + "&page=" + page; } url = url.replace(/page=[1-9][0-9]*/,"page="+page); }else if(url.indexOf("page=") > -1){ url = url.replace(/page=[1-9][0-9]*/,"page="+page); } location.href = url; } } //点击跳转 function pageChange(page,totalpage){ var url = window.location.href; if (Math.abs(page) > totalpage) page = totalpage; if(url.indexOf("page_") > -1) { url = url.replace(/page_[1-9][0-9]*/,"page_"+page); }else if (url.indexOf("page=") == -1) { if (url.indexOf("?") == -1) { url = url + "?page=" + page; }else{ url = url + "&page=" + page; } url = url.replace(/page=[1-9][0-9]*/,"page="+page); }else if(url.indexOf("page=") > -1){ url = url.replace(/page=[1-9][0-9]*/,"page="+page); } location.href = url; }