前端分页

xiaoxiao2021-02-28  7

/**  * 分页函数  * 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

})()

转载请注明原文地址: https://www.6miu.com/read-1750138.html

最新回复(0)