|
- var newUrl;
- var page_name='';
- var total_page=0;
- function getPager(url, sum, currnum, length,idTag,page_tag_name) {
- page_tag_name=page_tag_name+'=';
- page_name=page_tag_name;
- newUrl =url;
- sum=parseInt(sum);
- currnum=parseInt(currnum);
- length=parseInt(length);
- if (length >= sum) {
- document.getElementById(idTag).innerHTML= "";
- return "";
- }
- var showsum = "共";
- var showitem = "页";
- var showfirstpage = "首页";
- var showuppage = "<";
- var shownextpage = ">";
- var showlastpage = "尾页";
- var showjump = "跳转到";
- var showselect = "Go";
- // var showtotal = "共";
- // var showpage = "页";
- var pagerinfo = '';
- var sbinfo = '';
- sbinfo+="<div class='pager'>";
- var pagenum = 0;
- if (sum % length == 0) {
- pagenum = sum / length;
- pagenum = parseInt(pagenum);
- } else {
- pagenum = sum / length-0 + 1;
- pagenum = parseInt(pagenum);
- }
- total_page=pagenum;
- showfirstpage = "" +1;
- showlastpage = ""+pagenum;
- var first = "";
- if (url.indexOf("?") != -1) {
- first = "&";
- } else {
- first = "?";
- }
- var pageUrl = "";
- sbinfo+=(showsum + "<font color=\"gray\">" + pagenum + "</font>"
- + showitem + " ");
- if (1 == currnum) {
- sbinfo+=(showuppage + " ");
- } else {
- pageUrl = url + first +page_tag_name+ (currnum - 1);
- sbinfo+=("<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none; \" href=\""
- + pageUrl + "\" >" + showuppage + "</a> ");
- }
- var firstUrl = url + first +page_tag_name+ 1;
- sbinfo+=("<a class='paginationjs-prev J-paginationjs-previous' href=\"" + firstUrl + "\">"
- + showfirstpage + "</a> ");
- var tempstr = "";
- if (pagenum < 6) {
- var tag = 0;
- for (var i = 2; i < pagenum + 1 && i <= pagenum-1; i++) {
- pageUrl = url + first +page_tag_name+ i;
- if (i == currnum) {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl
- + "\" ><b><font color=\"gray\">"
- + i
- + "</font></b></a> ";
- } else {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl + "\" >" + i + "</a> ";
- }
- sbinfo+=(tempstr);
- if(i>=pagenum-1){
- tag = 1;
- }
- }
- } else if (currnum > pagenum - 1) {
- var tag = 0;
- sbinfo+=("...");
- for (var i = currnum - 4; i < pagenum + 1 && i <= pagenum-1; i++) {
- pageUrl = url + first +page_tag_name+ i;
- if (i == currnum) {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl
- + "\" ><b><font color=\"gray\">"
- + i
- + "</font></b></a> ";
- } else {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl + "\" >" + i + "</a> ";
- }
- sbinfo+=(tempstr);
- if(i>=pagenum-1){
- tag = 1;
- }
- }
- } else if (currnum < 4) {
- var tag = 0;
- for (var i = 2; i < currnum + 3 && i <= pagenum-1; i++) {
- pageUrl = url + first +page_tag_name+ i;
- if (i == currnum) {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl
- + "\" ><b><font color=\"gray\">"
- + i
- + "</font></b></a> ";
- } else {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl + "\" >" + i + "</a> ";
- }
- sbinfo+=(tempstr);
- if(i>=pagenum-1){
- tag = 1;
- }
- }
- if(tag == 0){
- sbinfo+=("...");
- }
- } else {
- if(currnum - 2 > 2){
- sbinfo+=("...");
- }else{
-
- }
- var tag = 0;
- for (var i = currnum - 2; i < currnum + 3 && i <= pagenum-1; i++) {
- pageUrl = url + first +page_tag_name+ i;
- if (i == currnum) {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl
- + "\" ><b><font color=\"gray\">"
- + i
- + "</font></b></a> ";
- } else {
- tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
- + pageUrl + "\" >" + i + "</a> ";
- }
- sbinfo+=tempstr;
- if(i>=pagenum-1){
- tag = 1;
- }
- }
- if(tag == 0){
- sbinfo+=("...");
- }
- }
- var endUrl = url + first +page_tag_name+ pagenum;
- sbinfo+=(" <a class='paginationjs-prev J-paginationjs-previous' href=\"" + endUrl + "\">"
- + showlastpage + "</a> ");
- if (currnum == pagenum) {
- sbinfo+=(shownextpage);
- } else {
- pageUrl = url + first +page_tag_name+ (currnum + 1);
- sbinfo+=("<a class='paginationjs-prev J-paginationjs-previous' href=\"" + pageUrl
- + "\">" + shownextpage + "</a>");
- }
- var selecturl = url + first;
- sbinfo+=(showjump
- + "<input id='goButton' onKeyUp='page_put_change(this,this.value)' class='form-control' style='display:inline-block;width: 40px;height:25px; margin-left:5px; margin-top:-4px' >"+"</input>");
- sbinfo+=("</input type='text'><button id='go' style='margin-top=-2px' onclick=\"go()\">GO</button>");
- pagerinfo = sbinfo;
- document.getElementById(idTag).innerHTML=pagerinfo;
- }
- function page_put_change(self_obj,value){
- var int_value=parseInt(value);
- if (total_page<int_value) {
- self_obj.value=total_page;
- }
- }
- function go(){
- var tt= document.getElementById("goButton").value;
- if (total_page<parseInt(tt)) {
- tt=total_page+'';
- }
- var first = "";
- if (newUrl.indexOf("?") != -1) {
- first = "&";
- } else {
- first = "?";
- }
- var listURL = newUrl+first+page_name+tt;
- // 跳转前将URL编码
- listURL = encodeURI(listURL);
- window.location.href = listURL;
- }
|