爱易网
IT新闻
IT新闻
爱易资讯
网站搭建
云虚拟主机教程
云服务器教程
Apache教程
IIS教程
Nginx教程
网站策划
站长文章
推广教程
淘宝客教程
网页设计
HTML教程
XHTML教程
CSS教程
HTML5教程
CSS3教程
JavaSript基础
JQuery教程
Node.js教程
前端技术
Ajax教程
Js特效
Xml教程
平面设计
页面UI设计
photoshop教程
程序开发
AI人工智能
Asp教程
Php教程
Asp.Net教程
Net Core教程
C#教程
Java教程
Jsp教程
开发技术
微信小程序教程
Uniapp开发教程
微信公众号开发
Andriod教程
IOS教程
DOS教程
Python教程
Docker教程
Windows Container教程
数据库
MSSQL教程
MySQL教程
Redis教程
Access教程
Oracle教程
数据库教程
操作系统
Linux教程
Windows教程
MAC教程
Cisco教程
交换机教程
防火墙教程
搜索
爱易网页
JavaSript
十分简单的兼容多浏览器Javascript实现分页功能
十分简单的兼容多浏览器Javascript实现分页功能
日期:2014-05-16 浏览次数:20380 次
非常简单的兼容多浏览器Javascript实现分页功能
首先,创建一个page.js文件,实现客户端分页的功能,代码如下:
/* * 客户端分页类 * @pageSize 每页显示记录数 * @tableID 分页表格ID * @tbodyID 分页表格TBODY的ID */ /* 构造 */ function PagingClass(pageSize,tableID,tbodyID) { this._pageSize = pageSize; //每页最大记录数 this._tableId = tableID; this._tBodyId = tbodyID; this._rowCount = 0;//记录数 this.pageCount = 0;//页数 this.pageIndex = 0;//页索引 this._curTable = null;//表格引用 this._curTBody = null;//要分页内容 this._curRows = 0;//记录行引用 this._oldTBody = null; this._initPaging(); //初始化; }; /* 初始化 */ PagingClass.prototype._initPaging = function(){ this._curTable = document.getElementById(this._tableId); this._curTBody = this._curTable.tBodies[this._tBodyId]; this._curRows = this._curTBody.rows; this._rowCount = this._curRows.length; try{ this._pageSize = (this._pageSize <= 0) || (this._pageSize>this._rowCount) ? this._rowCount : this._pageSize; this.pageCount = parseInt(this._rowCount%this._pageSize == 0 ? this._rowCount/this._pageSize : this._rowCount/this._pageSize+1); } catch(exception){} this._updateTableRows_(); }; /* 下一页 */ PagingClass.prototype.nextPage = function(){ if(this.pageIndex + 1 < this.pageCount){ this.pageIndex += 1; this._updateTableRows_(); } }; /* 上一页 */ PagingClass.prototype.prePage = function(){ if(this.pageIndex >= 1){ this.pageIndex -= 1; this._updateTableRows_(); } }; /* 首页 */ PagingClass.prototype.firstPage = function(){ if(this.pageIndex != 0){ this.pageIndex = 0; this._updateTableRows_(); } }; /* 尾页 */ PagingClass.prototype.lastPage = function(){ if(this.pageIndex+1 != this.pageCount){ this.pageIndex = this.pageCount - 1; this._updateTableRows_(); } }; /* 页定位方法 */ PagingClass.prototype.aimPage = function(iPageIndex){ if(iPageIndex > this.pageCount-1){ this.pageIndex = this.pageCount - 1; } else if(iPageIndex < 0){ this.pageIndex = 0; }else{ this.pageIndex = iPageIndex; } this._updateTableRows_(); }; /* 执行分页时,更新显示表格内容 */ PagingClass.prototype._updateTableRows_ = function(){ var iCurrentRowCount = this._pageSize * this.pageIndex; var iMoreRow = this._pageSize+iCurrentRowCount > this._rowCount ? this._pageSize+iCurrentRowCount - this._rowCount : 0; var tempRows = this._cloneRows_(); var removedTBody = this._curTable.removeChild(this._curTBody); var newTBody = document.createElement("TBODY"); newTBody.setAttribute("id", this._tBodyId); for(var i=iCurrentRowCount; i < this._pageSize+iCurrentRowCount-iMoreRow; i++){ newTBody.appendChild(tempRows[i]); } this._curTable.appendChild(newTBody); this._curRows = tempRows; this._curTBody = newTBody; }; /* 克隆原始操作行集合 */ PagingClass.prototype._cloneRows_ = function(){ var tempRows = []; for(var i=0; i<this._curRows.length; i++){ tempRows[i] = this._curRows[i].cloneNode(1); } return tempRows; };
然后,创建一个html页面,比如:
<table class="base_table" id="tbSeatList"> <thead> <tr> <th> 航空公司 </th> <th> 航线 </th> <th> 价格 </th> <th> 航班日期 </th> <th> 放位时间 </th> <th> 航班号 </th> <th> 放位数量
上一篇: ssh如何知道删除实体成不成功
下一篇: Javascript种,prototype研究
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
JavaScript各类父窗口与子窗口其间的操作(包括Iframe、window.open、window.showModalDialog)
如何用js设计一个日历出来?
在php中获取js克隆表的数据解决思路
关于Button和Div的从属性有关问题,也许不可能解决
div定位有关问题
获取鼠标现阶段位置的js
jquery 与 setInterval 不是老交情吗?
请教能否通过javascript改变自身的outerHTML
用javascript,如何获得表格中所点击的这一行的行数
推荐阅读
更多>
有没有C#Script?解决方案
javascript高级程序设计-札记
Jsp/Servlet温习笔记-第6章 JSP基础
javascript 前景怎样?解决方案
html中javascript小疑点
求个jquery打包,加载动画始终居中显示,代码已有,不会封装
JS 在IE跟FireFox中的区别(二)
window.open 打开页面 同时执行新页面中的函数解决思路
判断数组是不是已包含了某个元素的js函数
JSF2.0根本环境
javascript运算符总结
jsocks代理服务器跟客户端的试用
关于JQUERY UI 的TABS控件如何从外部更新TABS里的内容
EXTJs 掩藏 TABPanel window panel 水平 横轴 横向 滚动条
jsp页长相关
jsoup 兑现浏览器网页另存为
在applet顶用URLConnection访问servlet为什么没反应?同样的代码在jsp中就可以
怎么判断浏览器是否支持javascrip
一个容易的纯JS时间控件(非jQuery插件)
Servlet、Jsp乱码有关问题(二)