码迷,mamicode.com
首页 > Web开发 > 详细

一个比较轻巧好用的js分页插件,可ajax可url

时间:2015-07-06 11:57:29      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

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/  

一个比较轻巧好用的js分页插件,可ajax可url

标签:

原文地址:http://www.cnblogs.com/zenghansen/p/4623669.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!