You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

172 lines
5.2 KiB

  1. var newUrl;
  2. function getPager(url, sum, currnum, length,idTag) {
  3. newUrl =url;
  4. sum=parseInt(sum);
  5. currnum=parseInt(currnum);
  6. length=parseInt(length);
  7. if (length >= sum) {
  8. document.getElementById(idTag).innerHTML= "";
  9. return "";
  10. }
  11. var showsum = "共";
  12. var showitem = "页";
  13. var showfirstpage = "首页";
  14. var showuppage = "<";
  15. var shownextpage = ">";
  16. var showlastpage = "尾页";
  17. var showjump = "跳转到";
  18. var showselect = "Go";
  19. // var showtotal = "共";
  20. // var showpage = "页";
  21. var pagerinfo = '';
  22. var sbinfo = '';
  23. sbinfo+="<div class='pager'>";
  24. var pagenum = 0;
  25. if (sum % length == 0) {
  26. pagenum = sum / length;
  27. pagenum = parseInt(pagenum);
  28. } else {
  29. pagenum = sum / length-0 + 1;
  30. pagenum = parseInt(pagenum);
  31. }
  32. showfirstpage = "" +1;
  33. showlastpage = ""+pagenum;
  34. var first = "";
  35. if (url.indexOf("?") != -1) {
  36. first = "&";
  37. } else {
  38. first = "?";
  39. }
  40. var pageUrl = "";
  41. sbinfo+=(showsum + "<font color=\"gray\">" + pagenum + "</font>"
  42. + showitem + "   ");
  43. if (1 == currnum) {
  44. sbinfo+=(showuppage + " ");
  45. } else {
  46. pageUrl = url + first + "currpage=" + (currnum - 1);
  47. sbinfo+=("<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none; \" href=\""
  48. + pageUrl + "\" >" + showuppage + "</a> ");
  49. }
  50. var firstUrl = url + first + "currpage=" + 1;
  51. sbinfo+=("<a class='paginationjs-prev J-paginationjs-previous' href=\"" + firstUrl + "\">"
  52. + showfirstpage + "</a> ");
  53. var tempstr = "";
  54. if (pagenum < 6) {
  55. var tag = 0;
  56. for (var i = 2; i < pagenum + 1 && i <= pagenum-1; i++) {
  57. pageUrl = url + first + "currpage=" + i;
  58. if (i == currnum) {
  59. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  60. + pageUrl
  61. + "\" ><b><font color=\"gray\">"
  62. + i
  63. + "</font></b></a> ";
  64. } else {
  65. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  66. + pageUrl + "\" >" + i + "</a> ";
  67. }
  68. sbinfo+=(tempstr);
  69. if(i>=pagenum-1){
  70. tag = 1;
  71. }
  72. }
  73. } else if (currnum > pagenum - 1) {
  74. var tag = 0;
  75. sbinfo+=("...");
  76. for (var i = currnum - 4; i < pagenum + 1 && i <= pagenum-1; i++) {
  77. pageUrl = url + first + "currpage=" + i;
  78. if (i == currnum) {
  79. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  80. + pageUrl
  81. + "\" ><b><font color=\"gray\">"
  82. + i
  83. + "</font></b></a> ";
  84. } else {
  85. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  86. + pageUrl + "\" >" + i + "</a> ";
  87. }
  88. sbinfo+=(tempstr);
  89. if(i>=pagenum-1){
  90. tag = 1;
  91. }
  92. }
  93. } else if (currnum < 4) {
  94. var tag = 0;
  95. for (var i = 2; i < currnum + 3 && i <= pagenum-1; i++) {
  96. pageUrl = url + first + "currpage=" + i;
  97. if (i == currnum) {
  98. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  99. + pageUrl
  100. + "\" ><b><font color=\"gray\">"
  101. + i
  102. + "</font></b></a> ";
  103. } else {
  104. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  105. + pageUrl + "\" >" + i + "</a> ";
  106. }
  107. sbinfo+=(tempstr);
  108. if(i>=pagenum-1){
  109. tag = 1;
  110. }
  111. }
  112. if(tag == 0){
  113. sbinfo+=("...");
  114. }
  115. } else {
  116. if(currnum - 2 > 2){
  117. sbinfo+=("...");
  118. }else{
  119. }
  120. var tag = 0;
  121. for (var i = currnum - 2; i < currnum + 3 && i <= pagenum-1; i++) {
  122. pageUrl = url + first + "currpage=" + i;
  123. if (i == currnum) {
  124. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  125. + pageUrl
  126. + "\" ><b><font color=\"gray\">"
  127. + i
  128. + "</font></b></a> ";
  129. } else {
  130. tempstr = "<a class='paginationjs-prev J-paginationjs-previous' stlye=\"text-decoration: none;\" href=\""
  131. + pageUrl + "\" >" + i + "</a> ";
  132. }
  133. sbinfo+=tempstr;
  134. if(i>=pagenum-1){
  135. tag = 1;
  136. }
  137. }
  138. if(tag == 0){
  139. sbinfo+=("...");
  140. }
  141. }
  142. var endUrl = url + first + "currpage=" + pagenum;
  143. sbinfo+=(" <a class='paginationjs-prev J-paginationjs-previous' href=\"" + endUrl + "\">"
  144. + showlastpage + "</a> ");
  145. if (currnum == pagenum) {
  146. sbinfo+=(shownextpage);
  147. } else {
  148. pageUrl = url + first + "currpage=" + (currnum + 1);
  149. sbinfo+=("<a class='paginationjs-prev J-paginationjs-previous' href=\"" + pageUrl
  150. + "\">" + shownextpage + "</a>");
  151. }
  152. var selecturl = url + first;
  153. sbinfo+=(showjump
  154. + "<input id='goButton' class='form-control' style='display:inline-block;width: 40px;height:25px; margin-left:5px; margin-top:-4px' >"+"</input>");
  155. sbinfo+=("</input type='text'><button id='go' onclick=\"go()\">GO</button>");
  156. pagerinfo = sbinfo;
  157. document.getElementById(idTag).innerHTML=pagerinfo;
  158. }
  159. function go(){
  160. var tt= document.getElementById("goButton").value;
  161. var first = "";
  162. if (newUrl.indexOf("?") != -1) {
  163. first = "&";
  164. } else {
  165. first = "?";
  166. }
  167. var listURL = newUrl+first+"currpage="+tt;
  168. // 跳转前将URL编码
  169. listURL = encodeURI(listURL);
  170. window.location.href = listURL;
  171. }