前端分页

/**
 * 分页函数
 * pno--页数
 * psize--每页显示记录数
 * 分页部分是从真实数据行开始,因而存在加减某个常数,以确定真正的记录数
 * 纯js分页实质是数据行全部加载,通过是否显示属性完成分页功能
 **/
;(function() {
var Page = function(config) {
this.num = parseInt(config.id.children.length);
this.dom = config.id.children;
this.config = {
totalPage: 0, //总页数,
pno: 1, //当前页数
pageSize: 5 //每页显示行数
}
if(config && this.isPlainObject(config)) {
this.extend(this.config, config)
}
this.totalPage = 0;
this.init();
}
Page.prototype = {
init: function() {
var pageSize = this.config.pageSize;
var num = this.num;
var totalPage = this.totalPage;
var dom = this.dom;
var currentPage = this.config.pno; //当前页数
if(num / pageSize > parseInt(num / pageSize)) {
this.totalPage = parseInt(num / pageSize) + 1;
} else {
this.totalPage = parseInt(num / pageSize);
}
var startRow = (currentPage - 1) * pageSize + 1; //开始显示的行  31
var endRow = currentPage * pageSize; //结束显示的行   40
endRow = (endRow > num) ? num : endRow;
for(var i = 1; i < (num + 1); i++) {
var irow = dom[i - 1];
if(i >= startRow && i <= endRow) {
irow.style.display = "block";
} else {
irow.style.display = "none";
}
}
},
isPlainObject: function(obj) {
return 'isPrototypeOf' in obj && Object.prototype.toString.call(obj) === '[object Object]';
},
extend: function(obj1, obj2) {
for(var attr in obj2) {
obj1[attr] = obj2[attr]
}
},
pageUp: function() { //上一页
this.config.pno -= 1;
if(this.config.pno >= 1) {
this.init()
} else {
this.config.pno = 1;
}
},
pageDn: function() { //下一页
this.config.pno += 1;


if(this.config.pno <= Nthis.totalPage) {
this.init()
} else {
this.config.pno = this.totalPage
}


}
}
window.Page = Page

})()




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值