The paging functionality implemented by JavaScript [for use with the background]

Source: Internet
Author: User
Tags prev

1(function(root) {2 3         functionPage (params) {4 5              This. Otarget =document.getElementById (params.dom);6              This. fn =Params.fn;7              This. pagenumber =Params.pagenumber;8              This. Interval = Params.interval | | 2;9              This. page = 1;Ten              This. Start = 1; One              This. End = ( This. interval*2+1); A              -              This. Dom (); -              This. bind (); the         } -Page.prototype.dom=function(){ -              This. Last =true; -              This. Data = []; +  -             if( This. page > This. Interval && This. Page < This. pagenumber- This. Interval) {//core ideas, based on the current page number, according to the interval corresponding to the generation.  +                  This. Start = This. Page- This. Interval; A                  This. end = This. Page + This. Interval; at}Else if( This. Page <= This. Interval) {//if it is less than the interval, it is generated by default values.  -                  This. Start = 1; -                  This. End = ( This. interval*2+1);  -}Else if( This. Page >= This. pagenumber- This. Interval && This. Page <= This. PageNumber) { -                  This. Start = This. PageNumber-( This. interval*2+1); -                  This. end = This. pagenumber; in                  This. Last =false;//used to judge: Whether the final value is generated.  -             } to      +             if( This. page > 1){ -                  This.  Data.push (' <a href= ' javascript:; " class= "prev" > Prev </a> '); the                  This. Data.push (' ... ')); *             } $ Panax Notoginseng              for(varI= This. start;i<= This. end;i++){ -  the                 if( This. page = =i) { +                      This. Data.push (' <span> ' +i+ ' </span> '); A}Else{ the                      This. Data.push (' <a href= ' javascript:; " > ' +i+ ' </a> '); +                 } -                  $             } $              -             if( This. Last) { -                  This. Data.push (' ... ')); the                  This.  Data.push (' <a href= ' javascript:; " Class= "Last" > ' + This. pagenumber + ' </a> '); -             }Wuyi  the             if( This. Page < This. PageNumber) { -                  This.  Data.push (' <a href= ' javascript:; " Class= "Next" > next page </a> '); Wu             } -  About              This. otarget.innerhtml = This. Data.join (' '); $         } -Page.prototype.bind=function(){ -             var_this = This; -              This. otarget.onclick=function(EV) { A  +                 varE = EV | |event, theo = E.target | |e.srcelement; -                     Switch(o.classname) { $                          Case' Next ': _this.page++; Break; the                          Case' prev ': _this.page--; Break; the                          Case' Last ': _this.page = _this.pagenumber; Break; the                         default: the                             if(O.tagname = = ' A ' &&!/next|prev|last/. Test (O.classname)) { -_this.page =parseint (o.innerhtml); in}Else{ the                                 return false;//eliminates a second click on the current itself the                             } About                     } the _this.fn (_this.page); the _this.dom (); the              +             } -         } the BayiRoot. Page =function(params) { the             NewPage (params); the         } -}) (window)

Call Method:

1 Page ({2' Dom ': ' Pages ',//the Target box that hosts the paging content3' PageNumber ': 10,//Max pages4' Interval ': 2,//page interval. 5' FN ':function(num) {//Page number callback function6             7Console.log (num)//Displays the current page-out value. 8             9         }Ten});

The paging functionality implemented by JavaScript [for use with background]

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.