爱易网
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 浏览次数:20378 次
非常简单的兼容多浏览器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研究
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
JSR轨范,系统参数测试大全
要命的js,该怎么处理
js上载(原创)
如何获取一个元素其所包含 的元素?
透过实验窥探javascript的解析执行顺序
正则表达式的有关问题,
高分!分很容易拿的。将一个大的图片分割显示,该如何解决
JQuery属性判断 + JSON 循环带参交付
JS中的attachEvent、addEventListener怎么传递参数
推荐阅读
更多>
请大家无论怎么帮小弟我这个忙,多谢 了
javascript 浏览器检测 - 涵盖主流浏览器
js设置select某个选项选中,在ie7上不显示
百度有没有公交搜索的http接口?该如何处理
JavaScript中instanceof对于不同的构造器也许都返回true
深入显出JavaScript(1)—ECMAScript
confirm 怎样添加按钮?
JavaScript惯用特效
jquery.fn.extend的疑点
JS使用(资料很全) 更新
jQuery的dialog里的buttons如何弄.
Chrome扩展之content_scripts的执行时刻?解决方法
JS怎么获取指定对象上面的表单元素的值
JavaScript浮点数运算-精度有关问题
ajax 调用函数获取数据retun返回的是undefined 但是alert时却有值 请问一下是什么有关问题
DOJO学习札记:JavaScript(一)
求推荐学习JS的读物
同一页面不断刷新,怎么在js中定义全局变量
怎么实现日期加一天
ajax没法获取回调值