A good example of an AJAX paging

Source: Internet
Author: User
Tags query

The style can be customized, the call is simple, look directly at the example, the effect of the figure is as follows:

  1. <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
  2. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
  3. <title>ajax Paging </title>
  4. <body>
  5. <style>
  6. . pagination {font-family:tahoma;font-size:12px;height:22px;margin:5px 10px;text-align:right;}
  7. . pagination A,.page-cur,.page-start,.page-end,.page-disabled,.page-skip {
  8. height:22px;line-height:22px;margin:0 3px 0 0;text-align:center;vertical-align:middle;white-space:nowrap;}
  9. . pagination input {border-width:1px;}
  10. Page-start,. Pagination A,. Page-end,. page-disabled {border:1px solid #CCCCCC;p adding:0 5px;}
  11. . pagination a {text-decoration:none;}
  12. . page-cur {background-color: #FFEDE1; border:1px solid #FD6D01; color: #FD6D01; font-weight:700;padding:0 5px;}
  13. . page-disabled {color: #CCCCCC;}
  14. . page-skip {color: #666666;p adding:0 3px;}
  15. </style>
  16. <div id= "Pagenav" ></div>
  17. </body>
  18. <script>
  19. Testpage (1);
  20. function Testpage (curpage) {
  21. Supage (' Pagenav ', ' testpage ', ', ', curpage,100,5);
  22. }
  23. /**
  24. * @param {String} divname the DOM object ID rendered to the pager
  25. * @param {String} funname click the page number to perform the JS function of background query data
  26. * @param {Object} params the parameters of the background query data function, the order of the parameters is the sequence of the object, the current page must be set in the
  27. * The total number of records returned by the @param {String} sum background
  28. * @param {Boolean} pageSize the number of records displayed per page, default is 10
  29. */
  30. function Supage (divID, Funname, params, curpage, Total, pageSize) {
  31. var output = ' <div class= ' pagination ' > ';
  32. var pageSize = parseint (pageSize) >0? parseint (pageSize): 10;
  33. if (parseint (total) = = 0 parseint (total) = = ' NaN ') return;
  34. var totalpage = Math.ceil (total/pagesize);
  35. var curpage = parseint (curpage) >0? parseint (curpage): 1;
  36. To parse out the parameters from the Parameter object
  37. var param_str = ';
  38. if (typeof params = = ' object ') {
  39. For (o in params) {
  40. if (typeof params[o] = = ' string ') {
  41. Param_str + + Params[o] + ', ';
  42. }
  43. else{
  44. Param_str + = Params[o] + ', ';
  45. }
  46. }
  47. Alert (111);
  48. }
  49. Set Start Page number
  50. if (Totalpage > 10) {
  51. if ((curPage-5) > 0 && curpage < totalPage-5) {
  52. var start = curPage-5;
  53. var end = Curpage + 5;
  54. }
  55. else if (curpage >= (totalPage-5)) {
  56. var start = totalPage-10;
  57. var end = Totalpage;
  58. }
  59. else {
  60. var start = 1;
  61. var end = 10;
  62. }
  63. }
  64. else {
  65. var start = 1;
  66. var end = Totalpage;
  67. }
  68. Home control
  69. if (curpage>1) {
  70. Output + = ' <a href= ' javascript: ' +funname+ ' (' + param_str + ' 1); "title=" first page "class=" Page-first ">«</a>";
  71. }
  72. Else
  73. {
  74. Output + = ' <span class= ' page-disabled ' >«</span> ';
  75. }
  76. Previous Page Menu control
  77. if (curpage>1) {
  78. Output + = ' <a href= ' javascript: ' +funname+ ' (' + Param_str + (curPage-1) + '); "title=" previous page class= "Page-previous" >‹ </a> ';
  79. }
  80. else{
  81. Output + = ' <span class= ' page-disabled ' >‹</span> ';
  82. }
  83. Page number Show
  84. for (i = start; I <= end; i++) {
  85. if (i = = Curpage) {
  86. Output + = ' <a href= ' javascript:; "class=" page-cur "> ' + curpage + ' </a>";
  87. }
  88. else {
  89. Output + = ' <a href= ' javascript: ' +funname+ ' (' + param_str + i + '); > ' + i + ' </a> ';
  90. }
  91. }
  92. Next Page Menu control
  93. if (totalpage>1 && curpage<totalpage) {
  94. Output + = ' <a title= ' next page "href=" javascript: ' +funname+ ' (' +param_str + (curpage+1) + '); "class=" Page-next ">›</a" > ';
  95. }
  96. else{
  97. Output + = ' <span class= ' page-disabled ' >›</span> ';
  98. }
  99. Last Page control
  100. if (curpage<totalpage) {
  101. Output + = ' <a title= ' last page ' href= ' javascript: ' +funname+ ' (' +param_str + totalpage+ '); "class=" Page-end ">»</a" > ';
  102. }
  103. else{
  104. Output + = ' <span class= ' page-disabled ' >»</span> ';
  105. }
  106. Output + = ' </div> ';
  107. Render to Dom
  108. document.getElementById (divid). InnerHTML = output;
  109. };
  110. </script>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.