var pageNav = pageNav || {}; pageNav.fn = null; pageNav.pre = "pre"; pageNav.next = "next"; pageNav.nav = function (a, b) { if (1 >= b)return this.pn = this.p = 1, this.pHtml2(1); b < a && (a = b); var c = ""; 1 >= a ? a = 1 : (c += this.pHtml(a - 1, b, pageNav.pre), c += this.pHtml(1, b, "1")); this.p = a; this.pn = b; var d = 2, e = 9 > b ? b : 9; 7 <= a && (c += "...", d = a - 4, e = a + 4, e = b < e ? b : e); for (; d < a; d++)c += this.pHtml(d, b); c += this.pHtml2(a); for (d = a + 1; d <= e; d++)c += this.pHtml(d, b); e < b && (c = c + "..." + this.pHtml(b, b)); a < b && (c += this.pHtml(a + 1, b, pageNav.next)); return c }; pageNav.pHtml = function (a, b, c) { return" <a href='javascript:pageNav.go(" + a + "," + b + ");' class='pageNum'>" + (c || a) + "</a> " }; pageNav.pHtml2 = function (a) { return" <span class='cPageNum'>" + a + "</span> " }; pageNav.go = function (a, b) { document.getElementById("pageNav").innerHTML = this.nav(a, b); null != this.fn && this.fn(this.p, this.pn) }; /* <style> .pageNum{border: 1px solid #999;padding:2px 8px;display: inline-block;} .cPageNum{font-weight: bold;padding:2px 5px;} #pageNav a:hover{text-decoration:none;background: #fff4d8; } </style> * //$(function(){ //for jquery window.onload = (function(){ //optional set pageNav.pre="PRE3"; pageNav.next="NEXT"; // p:current page number. // pn: page sum. pageNav.fn = function(p,pn){ document.getElementById("test").innerHTML ="Page:"+p+" of "+pn + " pages."; //$("#test").text("Page:"+p+" of "+pn + " pages."); //for jquery }; //goto the page 3 of 33. pageNav.go(3,53); });*/
官方地址:https://code.google.com/p/page-nav-js-jquery/