JavaScript to implement php pseudo paging

Source: Internet
Author: User
Assume that a page contains a lot of data and cannot be displayed easily. if there is a player in it and you do not want the player to terminate when turning pages, this method can be used even though Ajax can be used, but with less data, this method is more advantageous. JS code is as follows:

The code is as follows:



// Maximum data volume
Var total = "100 ";
// Display Volume per page
Var pagesize = 10;
// Total number of pages
Var pagenum = Math. ceil (total/pagesize );
// Generate navigation
Function initpage (nowpage ){
Var pagenav = 'preview ';
For (I = 1; I <= pagenum; I ++ ){
Pagenav + = (I = nowpage )? ''+ I +'': ''+ I + '';
}
Pagenav + = 'next page ';
Document. getElementById ('Pages '). innerHTML = pagenav;
}

// Page flip
Function goToPage (page ){
Var start = (page-1) * pagesize;
Var max = page * pagesize;
For (vs = 0;
Var export bj = document. getElementById ('item _ '+ );
Obj. style. display = "none ";
}
If (max> total) max = total;
For (v = start; v
Var export bj = document. getElementById ('item _ '+ v );
Obj. style. display = "block ";
}
Initpage (page );
}

// Previous Page

Function up (nowpage ){
If (nowpage = 1) return false;
If (nowpage> 1) goToPage (nowpage-1 ));
}

// Next page

Function down (nowpage ){
If (nowpage = pagenum) return false;
If (nowpage
}





If the data is

  • .........


  • .........


  • ...........

  • ........


  • Then a navigation similar to this is displayed:

    Previous Page 1 2 3 4 Next Page

    Click the page number or the next page to switch to display.



    The time is too short. so much is said. if you do not understand the code, leave a message.

    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.