js 分页
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 分页的更多相关文章
- js分页小结
今天解决了JS分页的问题1 页码 给每页的内容套一个相同的类名 通过选择器加上.length或者.size() 来获得总页数2当前页的页码可以使用each(function(index,DOMsss ...
- 自己封装的JS分页功能[用于搭配后台使用]
* 2016.7.03 修复bug,优化代码逻辑 * 2016.5.25 修复如果找不到目标对象的错误抛出. * 2016.5.11 修复当实际页数(pageNumber)小于生成的页码间隔数时的bu ...
- jsp、js分页功能的简单总结
一.概述 首先,我们要明确为何需要分页技术,主要原因有以下: 1.分页可以提高客户体验度,适当地选择合适的数据条数,让页面显得更有条理,使得用户体验感良好,避免过多数据的冗余. 2.提高性能的需要.分 ...
- 一个重构的js分页类
// JavaScript Document /**//** * js分页类 * @param iAbsolute 每页显示记录数 * @param sTableId 分页表格属性ID值,为Strin ...
- 面向对象版js分页
基于前一个js分页,我将代码改成一个面向对象版的js分页,代码如下 http://peng666.github.io/blogs/pageobj <!DOCTYPE html> <h ...
- 纯js分页代码(简洁实用)
纯js写的分页代码. 复制代码代码如下: //每页显示字数 PageSize=5000; //分页模式 flag=2;//1:根据字数自动分页 2:根据[NextPage]分页 //默认页 start ...
- JS分页 + 获取MVC地址栏URL路径的最后参数
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...
- 浅谈js分页的几种方法
一个项目中必然会遇到分页这种需求的,分页可以使数据加载更合理,也让页面显示更美观,更有层次感!那么js分页到底如何实现呢?下面我就来讲一下三种循序渐进的方法 1.自己纯手写分页 更深入的去理解分页的意 ...
- JS分页条插件
目标 制作js分页导航jq插件,用于无刷新分页或者刷新分页 实现目标参考京东和天猫的分页条. 有四个固定按钮,前页码,后页码,首页,末页. 程序关键点在于计算中间页面的起止位置.逻辑是以当前页码为参照 ...
- js分页实例
js分页实例 案例1 1.js_pageusers.html <!DOCTYPE html> <html> <head> <title>js_pageu ...
随机推荐
- 【Scheme】序列的操作
1.序列的表示 序列 序列(表)是由一个个序对组合而成的,具体来说就是让每个序对的car部分对应这个链的条目,cdr部分则是下一个序对. 对于1->2->3->4这个序列我们可以表示 ...
- HttpSession 和 HttpSession
说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案.
- tabindex 去掉虚线
参考 https://bbs.csdn.net/topics/390165247 style="outline: none"
- php 更新array键值
$arr1 = array("loginname" => "username","psw" => "password& ...
- NumPy 统计函数
NumPy 统计函数 NumPy 提供了很多统计函数,用于从数组中查找最小元素,最大元素,百分位标准差和方差等. 函数说明如下: numpy.amin() 和 numpy.amax() numpy.a ...
- 承载地图的div如果隐藏再显示,则定位时会定位到页面左上角
承载地图的div如果隐藏再显示,则定位时会定位到页面左上角. 解决方法:不隐藏,改变div的高度.在div上利用z-index加一个新的不透明的div.
- Unity3D研究院之设置自动旋转屏幕默认旋转方向
如下图所示,在处理屏幕默认旋转方向的时候可以在这里进行选择,上下左右一共是4个方向. 策划的需求是游戏采用横屏,但是要求支持两个方向自动旋转,如下图所示,我的设置是这样的. Default Orien ...
- f5售后查询
登录: https://secure.f5.com/validate/validate.jsp http://boochem.blog.51cto.com/628505/633907
- 关于gcc、make和CMake的区别
CMake是一种跨平台编译工具,比make更为高级,使用起来要方便得多.CMake主要是编写CMakeLists.txt文件,然后用cmake命令将CMakeLists.txt文件转化为make所需要 ...
- 安装sql server 2008 提示错误 SQL Server 2005 Express 工具。 失败
安装sql server 2008 management,提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL Server 2005 Express 工具. 失败,已安装 ...