Javascript news title static paging code (without refreshing) _ javascript skills

Source: Internet
Author: User
A template that retrieves n records from the database and generates static data. Static Single pages, index pages are combined with Arrays Using JS.
A template that retrieves n records from the database and generates static data.
Static Single pages, index pages are combined with Arrays Using JS.
Because the record is just a title, a link, and the number of bytes is not too large,
Using js to use this large array for paging looks good and saves bandwidth!
Great, simple, practical, and recommended!
JS Code:

The Code is as follows:


Function title_array (title, link_add, store_time ){
This. title = title;
This. link_add = link_add;
This. store_time = store_time;
}
Var ii = 0;
Var item = new Array ();
Ii ++; item [ii] = new title_array ('Study endless 25', '#', '(, January 1, March 17 )');
Ii ++; item [ii] = new title_array ('Study endless 24', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 23', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('Study is endless 22', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 21', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 20', '#', '(, January 15, March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 11', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 18', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('Study endless 17', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 16', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('learning is endless 15', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 14', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('learning endless 13', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 12', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 11', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 10', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 9', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 8', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 7', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 6', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 5', '#', '(, March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 4', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('endless learning 3', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('learning is endless 2', '#', '(March 17 )');
Ii ++; item [ii] = new title_array ('learning is endless 1', '#', '(, January 1, March 17 )');
// Page to be displayed
Var currpage = 1;
// The number of information entries displayed on one page is 40.
Var pagesize = 5;
// The first page displayed for page number Maintenance
Var beginpage = 1;
// The last page displayed for page number Maintenance
Var endpages = 100;
// Display the content of a page
Function displaypage (onepage ){
If (onepage <1 ){
Alert ("arrived on the homepage ");
Return;
}
Var NumRecords;
If (item. length = 1 ){
NumRecords = item. length;
} Else {
NumRecords = item. length-1; // The total number of items. This is because the information is saved from the subscript [1.
}
// Return if no information is available
If (NumRecords <= 0 ){
Return false;
}
NumPages = Math. floor (NumRecords + (pagesize-1)/pagesize); // total number of pages
If (onepage> NumPages ){
Alert ("the last page has been reached ");
Return;
}
Currpage = onepage;
// The first line of the page
Var start = pagesize * (currpage-1) + 1;
If (NumRecords = 1 ){
Start = start-1;
}
If (start> = item. length) return;
// Load the page content
Var strText = "";
For (var I = 1; I <= pagesize/5; I ++ ){
StrText + ="

    "
    For (var j = 1; j <= 5; j ++ ){
    If (start <item. length ){
    StrText + ="
  • "+ Item [start]. title +" "+ item [start]. store_time +"
  • ";
    Start ++;
    }
    }
    StrText + ="

"
}
Document. getElementById ("title1"). innerHTML = strText;
// If the total number of pages is less than 5
If (NumPages <10 ){
Beginpage = 1;
Endpage = NumPages;
} Else {
// If the first five pages are displayed
If (currpage <= 5 & currpage> 0 ){
Beginpage = 1;
Endpage = 10;
}
// If the last five pages are displayed
If (currpage <= NumPages & currpage> (NumPages-9 )){
Beginpage = NumPages-9;
Endpage = NumPages;
}
// Other cases
If (currpage> 5 & currpage <(NumPages-9 )){
If (currpage> = (endpage + 1 )){
Beginpage + = 10;
Endpage + = 10;
}
If (currpage <= (beginpage-1 )){
Beginpage-= 10;
Endpage-= 10;
}
}
}
Var showtext = "";
If (NumPages> 0 ){
Showtext + = "<";
Showtext + = "Previous Page ";
Var currpages = currpage <NumPages-2? Currpage + 2: NumPages;
Var currpage1 = currpage <= 2? 1: currpage-2;
If (NumPages <= 10 ){
Currpage1 = 1;
Currpages = NumPages;
} Else if (currpage1> = 2 ){
Showtext + = "1 ";
If (currpage1> 2 ){
Showtext + = "...";
}
}
For (I = currpage1; I <= currpages; I ++ ){
If (currpage = (I )){
Showtext + = "" + I + "";
} Else {
Showtext + = "" + I + "";
}
}
If (NumPages> 10 & currpages <= NumPages-1 ){
If (currpages <NumPages-1 ){
Showtext + = "...";
}
Showtext + = "" + NumPages + "";
}
Showtext = showtext + "next page ";
Showtext = showtext + "> ";
}
Document. getElementById ("page1"). innerHTML = showtext;
}


Call:

The Code is as follows:




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.