Javascript generic paging Program

Source: Internet
Author: User

<SCRIPT type = "text/JavaScript">
Function multi (Num, perpage, currpage, mpurl ){
/********** Parameter description *********
The total number of num records provided by the server program.
Perpage records per page
Current page number of currpage
Mpurl page url (for example, list. php)
***************************/

// Calculate the total number of pages
If(Num % perpage = 0 ){
Pages = num/perpage;
}Else{
Pages = math. Floor (Num/perpage) + 1;
}

// Process the paging URL address. When there is a variable parameter, add "&" after it; otherwise, add "?";
// Mpurl = mpurl. Search (/? /)> 0? Mpurl + "&": mpurl + "? ";

If(Mpurl. Search ('/? /')> 0)
{
Mpurl = mpurl + "? ";
}
Else
{
Mpurl = mpurl + "&";
}

Document. Write ('col' + num + 'record ');

If(Currpage = 1 ){
Document. Write ('homepage preput ');
}Else{
// When the current page is not one page, the home page and the previous page are displayed.
Document. Write ('homepage preput ');
}

If(Currpage> = pages ){
Document. Write ('Next last page ');
}Else{
// When the current page is not the last page, the next page and the last page are displayed.
Document. Write ('Next last page ');
}

Document. Write ('page: '+ currpage +'/'+ pages +' page '+ perpage +'/page :');

// Pagination drop-down list for automatic redirect
Document. Write ("");
For(I = 1; I '+ I +' ');
}Else{
Document. Write ('page '+ I + ');
}
}
Document. Write ('');
}

Multi (123, 20, 'p. asp? Id = 1 ')

</SCRIPT>
<Script language = "JavaScript"> multi (123, 20, 'p. asp? Id = 1') </SCRIPT>
To display the paging code, you only need to insert the following statement: Multi (123, 20, 1, 'js_multipage.htm '), when setting specific parameters, you only need to display the relevant variables of your ASP or PHP program here, as shown in PHP: </scriptlanguage = "JavaScript"> multi (<? = $ Total?>, <? = $ Perpage?>, <? = $ Page?> , 'Index. php? Bid = 1' </script

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.