爱易网
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 浏览次数:20347 次
非常简单的兼容多浏览器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> 放位数量
上一篇: javascript兑现手机触摸屏左右(上下)滚动(javascript感知滑屏方向)
下一篇: Javascript种,prototype研究
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
jsp中兑现分页查询
图片显示与隐藏,该如何处理
javascript验证简单的数学公式该怎么写?多谢
js 获取代码位置的dom元素解决方法
<SCRIPT LANGUAGE=javascript FOR=OA EVENT=NotifyCtrlReady> 这里面加入FOR 和 EVENT是什么意思?解决思路
ASP怎么讲查询结果打印成可转换成JSON的字符串
jquery页面元素下上移动示例
java编纂json要用的jar包
javascript 简略倒计时
推荐阅读
更多>
在EditPlus中配备JSHint插件,助你提高JS代码质量
关于头HTML文件的有关问题~
关于window.opener.document.body).children("div1")与clone,该怎么处理
javascript 变换数字千分符
Jquery怎么实现div的移动
JSP标签c:forEach范例
帮忙看看这段幻灯片程序为什么有时不行,有时就可以。解决办法
javascript应验
请问一个JAVASCRIPT有关问题
js模拟鼠标点符号击动作
JS兑现marquee滚动效果
Ajax中xmlhttp.responseText乱码有关问题,用尽了各种办法啊各位大侠帮忙看看
打开一个网址时如何把里面的密码文本框的值也一并的写下
关于区域滚动与元素定位有关问题
javascript简略获取当前日期和时间
jQuery UI插件在dialog中展示Ajax获取的json数据
模拟onclick事件执行。该如何解决
关于日期显示的有关问题
Jquery有关问题,或者js能解决也行
FCKeditor在jsp中被调用的模式和定制工具栏