JS Multi-function Paging component Laypage use method _javascript skills

Source: Internet
Author: User

The main purpose of this article is to share the Laypage multi-functional JS paging component specific operating methods for your reference, the specific content as follows

PHP section

function index () {
  header (' Content-type:text/html;charset=utf-8 ');
  Gets the current page number, the default first page, sets the default display bar per page
  $nowpage = I (' Get.page ', 1, ' intval ');
  $limits = 8;
  Gets the total number of bars
  $count = M (' Article ')-> where (' status ' =>array (' Egt ', 0))-> count ();
  Calculates the total page
  $allpage = ceil ($count/$limits);
  $allpage = Intval ($allpage);
    
  $lists = M (' Article ')-> where (array (' Status ' =>array (' Egt ', 0))
          -> page ($nowpage, $limits)//page method paging C12/>-> order (' createtime desc ')
          -> Select ();
  
  Jump paging output
  $this-> Assign (' lists ', $lists);
  $this-> Assign (' Allpage ', $allpage);
  $this-> Assign (' Nowpage ', $nowpage);
  $this->display ();
  /*//Ajax paging output
  $info = Array (' lists ' => $lists, ' allpage ' => $allpage, ' nowpage ' => $nowpage);
  $this->ajaxreturn ($info, ' json ');
  */
  
 }

JS Laypage (new version) jump pagination

Paging
laypage ({
  cont: ' show_pages ',//Paging container pages
  : ' {$allpage} ',   //Total pages
  skip:true,//Open Hop page
  Curr:function () {
    var page = ' {$nowpage} ';//Current page (background-acquired)
    return page page:1;//back to current page value
  } (),
  jump:f Unction (E, first) {//triggers a paging callback (after clicking the page number)
    if (!first) {//must be added, otherwise the Var URL will be refreshed indefinitely
      = "{: U" (' Article/index ', Array (' page ' => ' Pageval ')} ";
      var nowpage = E.curr; (clicked page number)
      urls = urls.replace (' Pageval ', nowpage);//Replace link styles and page numbers
      window.location.href = URLs;
    }
 });

JS Laypage (new version) Ajax paging

Function Demo (curr) {
  $.getjson (' {: U (' Article/index ')} ', {
    Page:curr//To server-side parameters, here is demo
  }, function (res) {//The JSON results returned by the server//
    This handles the content of the data in Res.lists, using the HTML () method to display
    //slightly ...
    
    Display Paging
    laypage ({
      cont: ' show_pages ',//Container
      pages:res.allpage,//   total pages (backstage)
      Curr:res.nowpage,/ /Current page (background-acquired)
      jump:function (obj, i) {//Trigger paging callback (after clicking Page number)
        if (!first) {//Click the Jump page to trigger the function itself, and pass the current page: Obj.curr
          demo (Obj.curr);//(Clicked page number)}
        }
    )
 ;}; Initialize run
demo ();

The above is the entire content of this article, I hope to learn more about the page component Laypage Help.

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.