html代码:

   <div id="paging_wrap" class="paging-wrap"></div>

css代码: 

div#paging_wrap {
padding-right: 3px;
padding-left: 3px;
padding-bottom: 3px;
margin: 20px 0px;
padding-top: 15px;;
text-align: center
} div#paging_wrap a {
border: #dedfde 1px solid;
padding-right: 6px;
background-position: 50% bottom;
padding-left: 6px;
padding-bottom: 2px;
color: #0061de;
margin-right: 3px;
padding-top: 2px;
text-decoration: none
} div#paging_wrap a:hover {
border: #000 1px solid;
background-image: none;
color: #fff;
background-color: #0061de
} div#paging_wrap a:active {
border-right: #000 1px solid;
border-top: #000 1px solid;
background-image: none;
border-left: #000 1px solid;
color: #fff;
border-bottom: #000 1px solid;
background-color: #0061de
} div#paging_wrap span.current {
padding-right: 6px;
padding-left: 6px;
font-weight: bold;
padding-bottom: 2px;
color: #ff0084;
margin-right: 3px;
padding-top: 2px
} div#paging_wrap span.disabled {
padding-right: 6px;
padding-left: 6px;
padding-bottom: 2px;
color: #adaaad;
margin-right: 3px;
padding-top: 2px
}

js代码:

//事件基础类
(function() {
var EventBase = function() { this.addListener = function(type, listener) {
getListener(this, type, true).push(listener);
} this.removeListener = function(type, listener) {
var listeners = getListener(this, type);
for (var i = 0; i < listeners.length; i++) {
if (listeners[i] == listener) {
listeners.splice(i, 1);
return;
}
}
} this.fireEvent = function(type) {
var listeners = getListener(this, type), r, t, k;
if (listeners) {
k = listeners.length;
while (k--) {
t = listeners[k].apply(this, arguments);
if (t !== undefined) {
r = t;
}
}
}
if (t = this['on' + type.toLowerCase()]) {
r = t.apply(this, arguments);
}
return r;
}
} function getListener(obj, type, force) {
var allListeners;
type = type.toLowerCase();
return ((allListeners = (obj.__allListeners || force
&& (obj.__allListeners = {}))) && (allListeners[type] || force
&& (allListeners[type] = [])));
} window['EventBase'] = EventBase;
})(); // 分页类
var Page = function(pageCanvas) {
this.recordCount;
this.pageSize;
this.numericButtonCount;
this.pageCanvas = pageCanvas;
this.pageIndex = 1;
} Page.prototype = new EventBase(); Page.prototype.getPageHtml = function() {
this.pageCount = Math.ceil(this.recordCount / this.pageSize);
var prev = this.pageIndex == 1 ? " <span class='disabled'>上一页</span>"
: " <span class=''><a href='javascript:;' pageindex='"
+ (this.pageIndex - 1) + "'>上一页</a></span> ";
var next = this.pageCount <= this.pageIndex ? " <span class='disabled'>下一页</span>"
: " <span class='current'><a href='javascript:;' pageIndex='"
+ (this.pageIndex + 1) + "'>下一页</a></span>";
var first = this.pageIndex == 1 ? "<span class='current'>1</span>..."
: "<span><a href='javascript:;' pageindex='1'>1</a></span>...";
var last = this.pageCount <= this.pageIndex ? "...<span class='current'>"
+ this.pageCount + "</span>"
: "...<span><a href='javascript:;' pageindex='" + (this.pageCount) + "'>"
+ this.pageCount + "</a></span>";
var pageStr = "" var pageMathIndex = Math.floor(this.numericButtonCount / 2);
var pageStartIndex;
var pageEndIndex; if (this.pageCount < this.numericButtonCount) {
pageStartIndex = 1
pageEndIndex = this.pageCount;
} else {
if (this.pageCount - pageMathIndex < this.pageIndex) {
pageStartIndex = this.pageCount - this.numericButtonCount + 1;
pageEndIndex = this.pageCount;
} else {
if (this.pageIndex - pageMathIndex < 1) {
pageStartIndex = 1;
pageEndIndex = this.numericButtonCount;
} else {
pageStartIndex = this.pageIndex - pageMathIndex;
pageEndIndex = this.pageIndex + pageMathIndex;
}
} } for (var i = pageStartIndex; i <= pageEndIndex; i++) {
if (this.pageIndex == i)
pageStr += " <span class='current'>" + i + "</span>"
else
pageStr += " <span><a href='javascript:;' pageindex='" + i + "'>" + i
+ "</a></span>";
} if (pageStartIndex == 1)
first = '';
if (pageEndIndex == this.pageCount)
last = '';
// pageStr = first + prev + pageStr + next + last;
pageStr = prev + first + pageStr + last + next;
return pageStr;
} Page.prototype.onPageChanged = function(pageIndex) {
this.pageIndex = pageIndex;
this.fireEvent('pageChanged');
} Page.prototype.pageEvent = function(page) {
this.onclick = function(e) {
e = e || window.event;
t = e.target || e.srcElement;
if (t.tagName == "A")
page.onPageChanged(parseInt(t.getAttribute("pageindex")));
}
} Page.prototype.render = function() {
var pageCanvas = document.getElementById(this.pageCanvas);
pageCanvas.innerHTML = this.getPageHtml();
this.pageEvent.call(pageCanvas, this);
} Page.prototype.initialize = function() {
this.onPageChanged(this.pageIndex);
}
function pageInit() {

    var p = new Page( 'paging_wrap' );
//总记录数
p.recordCount = selectDtzyCount();
//分页按扭数
p.numericButtonCount = 10;
//每页记录数
p.pageSize = 5;
//当点击分页时触发此事件。 一些外加的效果可以放在此处, 如加载数据
p.addListener( 'pageChanged', function() {
//列表内容
init(p.pageIndex, p.pageSize);
p.render();
} );
p.initialize();
}

js 分页的更多相关文章

  1. js分页小结

     今天解决了JS分页的问题1 页码 给每页的内容套一个相同的类名 通过选择器加上.length或者.size() 来获得总页数2当前页的页码可以使用each(function(index,DOMsss ...

  2. 自己封装的JS分页功能[用于搭配后台使用]

    * 2016.7.03 修复bug,优化代码逻辑 * 2016.5.25 修复如果找不到目标对象的错误抛出. * 2016.5.11 修复当实际页数(pageNumber)小于生成的页码间隔数时的bu ...

  3. jsp、js分页功能的简单总结

    一.概述 首先,我们要明确为何需要分页技术,主要原因有以下: 1.分页可以提高客户体验度,适当地选择合适的数据条数,让页面显得更有条理,使得用户体验感良好,避免过多数据的冗余. 2.提高性能的需要.分 ...

  4. 一个重构的js分页类

    // JavaScript Document /**//** * js分页类 * @param iAbsolute 每页显示记录数 * @param sTableId 分页表格属性ID值,为Strin ...

  5. 面向对象版js分页

    基于前一个js分页,我将代码改成一个面向对象版的js分页,代码如下 http://peng666.github.io/blogs/pageobj <!DOCTYPE html> <h ...

  6. 纯js分页代码(简洁实用)

    纯js写的分页代码. 复制代码代码如下: //每页显示字数 PageSize=5000; //分页模式 flag=2;//1:根据字数自动分页 2:根据[NextPage]分页 //默认页 start ...

  7. JS分页 + 获取MVC地址栏URL路径的最后参数

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

  8. 浅谈js分页的几种方法

    一个项目中必然会遇到分页这种需求的,分页可以使数据加载更合理,也让页面显示更美观,更有层次感!那么js分页到底如何实现呢?下面我就来讲一下三种循序渐进的方法 1.自己纯手写分页 更深入的去理解分页的意 ...

  9. JS分页条插件

    目标 制作js分页导航jq插件,用于无刷新分页或者刷新分页 实现目标参考京东和天猫的分页条. 有四个固定按钮,前页码,后页码,首页,末页. 程序关键点在于计算中间页面的起止位置.逻辑是以当前页码为参照 ...

  10. js分页实例

    js分页实例 案例1 1.js_pageusers.html <!DOCTYPE html> <html> <head> <title>js_pageu ...

随机推荐

  1. cf-Global Round2-D. Frets On Fire(二分)

    题目链接:http://codeforces.com/contest/1119/problem/D 题意:给n(<=1e5)个数s[i],i=1..n,(0<=s[i]<=1e18) ...

  2. 两条线段求交点+叉积求面积 poj 1408

    题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...

  3. 中国剩余定理模板 51nod 1079

    题目链接:传送门 推荐博客:https://www.cnblogs.com/freinds/p/6388992.html (证明很好,代码有误). 1079 中国剩余定理  基准时间限制:1 秒 空间 ...

  4. 这篇说的是Unity Input 输入控制器

    关于Unity3D是什么.我就不多做解释了.由于工作原因,该系列原创教程不定期更新.每月必然有更新.谢谢各位 Unity Input---输入控制管理器: Edit->Project Setti ...

  5. const和volatile分析

    c语言中const修饰的变量是只读的,不能直接作为赋值号的左值,其本质还是变量:会占用内存空间:本质上const在编译器有用,运行时无用(还是可以通过指针改变它的值) ; int *p=&ab ...

  6. C语言之栈区、堆区

    一 局部变量存放在栈区中,函数调用结束后释放内存空间. #include "stdio.h"; #include "stdlib.h"; int *getNum ...

  7. TZOJ 3315 买火车票(线段树区间最小值)

    描述 Byteotian州铁道部决定赶上时代,为此他们引进了城市联网.假设城市联网顺次连接着n 个市从1 到n 编号(起始城市编号为1,终止城市编号为n).每辆火车有m个座位且在任何两个运送更多的乘客 ...

  8. ubuntu下安装mysql及常用操作

    1.可通过ps -ef | grep mysql命令查看系统中是否有安装mysql 如果出现类似上述的页面,就证明是已经安装过了mysql,否则就是没有. 2.安装mysql 很简单,只需要键入如下命 ...

  9. linux命令学习之:tar

    tar命令可以为linux的文件和目录创建档案.利用tar,可以为某一特定文件创建档案(备份文件),也可以在档案中改变文件,或者向档案中加入新的文件.tar最初被用来在磁带上创建档案,现在,用户可以在 ...

  10. 本地推送UILocalNotification的一些简单方法

    1.添加本地推送,需要在app添加推送.可以根据通知的userInfo的不同的键值对来区分不同的通知 UILocalNotification *notification = [[UILocalNoti ...