Native JavaScript implementation of the paging plugin Pagenav_jquery

Source: Internet
Author: User

This is the use of native JavaScript implementation of the paging plug-in Pagenav, page number display jquery Plug-ins, only need to exist #pagenav, you will be displayed in the page number, the call can be based on the need to rewrite the Go method. (jquery dependencies removed) ....

The plug-in code is as follows:

/* ************************** Author:keel (keel.sike@gmail.com) ************************** page number shows the jquery plugin, only need to exist #pagen
 AV, the page number appears in it. You can override the Go method as needed before calling. (Removal of jquery dependencies) ************************** Example (note: Placing an HTML object with ID pagenav on the page)://The custom method that is triggered when the page number is changed, p is the current page number, PN is the total page Pagenav.fn = f
 Unction (P,PN) {alert (p+ "," +PN);
 };

 Initial jump to page 3rd, a total of 33 pages pagenav.go (3,33); * * var Pagenav = Pagenav | |
{};
Pagenav.fn = null;
    P is current page number, PN is total page pagenav.nav = function (p, PN) {//Only one page, direct display 1 if (PN <= 1) {THIS.P = 1;
    THIS.PN = 1;
  return THIS.PHTML2 (1);
  } if (PN < p) {p = pn;
  };
  var re = "";
  The first page if (P <= 1) {p = 1;
    else {//Non first page re + = this.phtml (p-1, pn, "prev");
  Always show first page number re + = this.phtml (1, pn, "1");
  //Corrected page number THIS.P = p;

  THIS.PN = PN;
  Start Page number var start = 2; var end = (PN < 9)?
  Pn:9;
    Whether to display the forward ellipsis, that is, the start page number greater than 10 if (p >= 7) {re = "...";
    start = p-4;
    var e = p + 4; End = (PN < e)?
  Pn:e; for (var i = sTart; I < P;
  i++) {Re + = this.phtml (i, PN);
  };
  Re + = THIS.PHTML2 (p);
  for (var i = p + 1; I <= end; i++) {Re + = this.phtml (i, PN);
  };
    if (end < PN) {re = "...";
  Displays the last page page number, if not necessary remove the following sentence re + = this.phtml (pn, PN);
  };
  if (P < pn) {re + = this.phtml (p + 1, PN, next page);
  };
return re;
};
  Show non-current page pagenav.phtml = function (PageNo, PN, Showpageno) {Showpageno = Showpageno | | pageno; var H = "<a href=" javascript:pageNav.go ("+ PageNo +", "+ pn +"); ' class= ' pagenum ' > ' + Showpageno + ' </a> '
  ;

return H;
};
  Displays the current page PAGENAV.PHTML2 = function (PageNo) {var H = "<span class= ' Cpagenum ' >" + pageno + "</span>";
return H;
}; Output page number, you can override this method as needed pagenav.go = function (p, PN) {//$ ("#pageNav"). HTML (This.nav (P,PN));//If you use jquery for this sentence Document.getel
  Ementbyid ("Pagenav"). InnerHTML = This.nav (P, PN);
  if (This.fn!= null) {This.fn (THIS.P, THIS.PN);
};

 };

The effect is as follows:

Demo Address: http://demo.jb51.net/js/2014/pagenav/have the need for a friend of their own chop code it, very simple, I do not provide direct download

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.