search
Homephp教程php手册很好的一个ajax分页实例

 

样式可以自定义,调用简单,直接看实例了,效果图如下:

 

  1. nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2.   
  3.   
  4.   
  5. ajax分页  
  6.   
  7.   
  8.   
  9. .pagination {font-family: Tahoma;font-size: 12px;height: 22px;margin: 5px 10px;text-align: right;}  
  10. .pagination a,.page-cur,.page-start,.page-end,.page-disabled,.page-skip {  
  11. height:22px;line-height:22px;margin:0 3px 0 0;text-align:center;vertical-align:middle;white-space:nowrap;}  
  12. .pagination input {border-width: 1px;}  
  13. .page-start, .pagination a, .page-end, .page-disabled {border: 1px solid #CCCCCC;padding: 0 5px;}  
  14. .pagination a {text-decoration: none;}  
  15. .page-cur {background-color: #FFEDE1;border: 1px solid #FD6D01;color: #FD6D01;font-weight: 700;padding: 0 5px;}  
  16. .page-disabled {color: #CCCCCC;}  
  17. .page-skip {color: #666666;padding: 0 3px;}  
  18.   
  19.   
  20.   
  21.   
  22.   
  23. <script> </script>
  24. testPage(1);  
  25. function testPage(curPage){  
  26.   
  27.         supage('pageNav','testPage','',curPage,100,5);  
  28.   
  29. }  
  30.   
  31.   
  32. /** 
  33.  
  34.  * @param {String} divName 分页导航渲染到的dom对象ID 
  35.  * @param {String} funName 点击页码需要执行后台查询数据的JS函数 
  36.  * @param {Object} params 后台查询数据函数的参数,参数顺序就是该对象的顺序,当前页面一定要设置在里面的 
  37.  * @param {String} total 后台返回的总记录数 
  38.  * @param {Boolean} pageSize 每页显示的记录数,默认是10 
  39.  */  
  40. function supage(divId, funName, params, curPage, total, pageSize){  
  41.     var output = '
    ';  
  42.     var pageSize = parseInt(pageSize)>0 ? parseInt(pageSize) : 10;  
  43.     if(parseInt(total) == 0  parseInt(total) == 'NaN') return;  
  44.     var totalPage = Math.ceil(total/pageSize);  
  45.     var curPage = parseInt(curPage)>0 ? parseInt(curPage) : 1;  
  46.       
  47.     //从参数对象中解析出来各个参数  
  48.     var param_str = '';  
  49.     if(typeof params == 'object'){  
  50.         for(o in params){  
  51.             if(typeof params[o] == 'string'){  
  52.                param_str += '\'' + params[o] + '\',';  
  53.             }  
  54.             else{  
  55.                param_str += params[o] + ',';  
  56.             }  
  57.         }  
  58.         //alert(111);  
  59.     }  
  60.     //设置起始页码  
  61.     if (totalPage > 10) {  
  62.         if ((curPage - 5) > 0 && curPage 
  63.             var start = curPage - 5;  
  64.             var end = curPage + 5;  
  65.         }  
  66.         else if (curPage >= (totalPage - 5)) {  
  67.             var start = totalPage - 10;  
  68.             var end = totalPage;  
  69.         }  
  70.         else {  
  71.             var start = 1;  
  72.             var end = 10;  
  73.         }  
  74.     }  
  75.     else {  
  76.         var start = 1;  
  77.         var end = totalPage;  
  78.     }  
  79.       
  80.     //首页控制  
  81.     if(curPage>1){  
  82.         output += '«';  
  83.     }  
  84.     else  
  85.     {  
  86.         output += '« ';  
  87.     }  
  88.     //上一页菜单控制  
  89.     if(curPage>1){  
  90.         output += '';  
  91.     }  
  92.     else{  
  93.         output += '';  
  94.     }  
  95.       
  96.     //页码展示  
  97.     for (i = start; i 
  98.         if (i == curPage) {  
  99.             output += '' + curPage + '';  
  100.         }  
  101.         else {  
  102.             output += '' + i + '';  
  103.         }  
  104.     }  
  105.     //下一页菜单控制  
  106.     if(totalPage>1 && curPage
  107.         output += '';  
  108.     }  
  109.     else{  
  110.         output += '';  
  111.     }  
  112.     //最后页控制  
  113.     if(curPage
  114.         output += '»';  
  115.     }  
  116.     else{  
  117.         output += '»';  
  118.     }  
  119.       
  120.     output += '
';  
  •     //渲染到dom中  
  •     document.getElementById(divId).innerHTML = output;  
  • };  
  •   


  • Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Article

    Hot Tools

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    DVWA

    DVWA

    Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    SecLists

    SecLists

    SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools