爱易网
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 浏览次数:20383 次
非常简单的兼容多浏览器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研究
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
【JS惯用代码】正则表达式验证
用js回模拟做出alert,confirm,poropmt对话框的效果
Extjs速度提升有关问题
Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
请问这个要如何实现·按标签分类搜索
任何数据类型都可以转换成布尔部类
ExtJs 动态增添表单
如何用JS在HTML中插入缺少的标签
怎么点击按钮弹出窗口
推荐阅读
更多>
js兑现 鼠标拖动背景图片
ExtJs Combobox绑值有关问题
一个页面跳转到另一个页面的tab选项卡的指定页上,该如何处理
Resin3 JSP预编译兑现
showModalDialog窗口的大小有限制吗?解决方案
请问js导航子菜单缩放错位有关问题
解决了myeclipse由于js乱码而使得程序需要这个js的地方运行不了
自各儿做的jquery放大镜效果插件,运行提示e没有定义
怎么在本地使用javascript修改当前网页内容
JS乘法求积有关问题
高效率判断星期几的javascript代码
jsonplugin的运用
javascript 最惯用的技巧
sniper.js脚本框架中增多常用数据类型判断
js报表光棒效果3种解决方案,支持动态生成表格
jquery javascript ajax常常用到的(一)
js javascript 鼠标控制图片上下滚动带自动翻滚,图片滑动新闻展示
ExtJs事件(自定义事件、on、eventManager)示范
【急】如何把javascript里的效果放到div标签中
JS 正则表达式有关问题,保留一位小数,不四舍五入,如果是整数就匹配整数本身