function page(_ref) { var pagesize = _ref.pagesize, pagetotal = _ref.pagetotal, curpage = _ref.curpage, id = _ref.id, getpage = _ref.getpage, showpagetotalflag = _ref.showpagetotalflag, showskipinputflag = _ref.showskipinputflag, pageamount = _ref.pageamount, datatotal = _ref.datatotal; if(!pagesize){ pagesize = 0 }; if(!pagesize){ pagesize = 0 }; if(!pagetotal){ pagetotal = 0 }; if(!pageamount){ pageamount = 0 }; if(!datatotal){ datatotal = 0 }; this.pagesize = pagesize || 5; //分页个数 this.pagetotal = pagetotal; //总共多少页 this.pageamount = pageamount; //每页多少条 this.datatotal = datatotal; //总共多少数据 this.curpage = curpage || 1; //初始页码 this.ul = document.createelement('ul'); this.id = id; this.getpage = getpage; this.showpagetotalflag = showpagetotalflag || false; //是否显示数据统计 this.showskipinputflag = showskipinputflag || false; //是否支持跳转 if(datatotal >0 &&pagetotal>0){ this.init(); }else{ console.error("总页数或者总数据参数不对") } }; // 给实例对象添加公共属性和方法 page.prototype = { init: function init() { var pagination = document.getelementbyid(this.id); pagination.innerhtml = ''; this.ul.innerhtml = ''; pagination.appendchild(this.ul); var that = this; //首页 that.firstpage(); //上一页 that.lastpage(); //分页 that.getpages().foreach(function (item) { var li = document.createelement('li'); if (item == that.curpage) { li.classname = 'active'; } else { li.onclick = function () { that.curpage = parseint(this.innerhtml); that.init(); that.getpage(that.curpage); }; } li.innerhtml = item; that.ul.appendchild(li); }); //下一页 that.nextpage(); //尾页 that.finalpage(); //是否支持跳转 if (that.showskipinputflag) { that.showskipinput(); } //是否显示总页数,每页个数,数据 if (that.showpagetotalflag) { that.showpagetotal(); } }, //首页 firstpage: function firstpage() { var that = this; var li = document.createelement('li'); li.innerhtml = '首页'; this.ul.appendchild(li); li.onclick = function () { var val = parseint(1); that.curpage = val; that.getpage(that.curpage); that.init(); }; }, //上一页 lastpage: function lastpage() { var that = this; var li = document.createelement('li'); li.innerhtml = '上一页'; if (parseint(that.curpage) > 1) { li.onclick = function () { that.curpage = parseint(that.curpage) - 1; that.init(); that.getpage(that.curpage); }; } else { li.classname = 'disabled'; } this.ul.appendchild(li); }, //分页 getpages: function getpages() { var pag = []; if (this.curpage <= this.pagetotal) { if (this.curpage < this.pagesize) { //当前页数小于显示条数 var i = math.min(this.pagesize, this.pagetotal); while (i) { pag.unshift(i--); } } else { //当前页数大于显示条数 var middle = this.curpage - math.floor(this.pagesize / 2), //从哪里开始 i = this.pagesize; if (middle > this.pagetotal - this.pagesize) { middle = this.pagetotal - this.pagesize + 1; } while (i--) { pag.push(middle++); } } } else { console.error('当前页数不能大于总页数'); } if (!this.pagesize) { console.error('显示页数不能为空或者0'); } return pag; }, //下一页 nextpage: function nextpage() { var that = this; var li = document.createelement('li'); li.innerhtml = '下一页'; if (parseint(that.curpage) < parseint(that.pagetotal)) { li.onclick = function () { that.curpage = parseint(that.curpage) + 1; that.init(); that.getpage(that.curpage); }; } else { li.classname = 'disabled'; } this.ul.appendchild(li); }, //尾页 finalpage: function finalpage() { var that = this; var li = document.createelement('li'); li.innerhtml = '尾页'; this.ul.appendchild(li); li.onclick = function () { var yyfinalpage = that.pagetotal; var val = parseint(yyfinalpage); that.curpage = val; that.getpage(that.curpage); that.init(); }; }, //是否支持跳转 showskipinput: function showskipinput() { var that = this; var li = document.createelement('li'); li.classname = 'totalpage'; var span1 = document.createelement('span'); span1.innerhtml = '跳转至'; li.appendchild(span1); var input = document.createelement('input'); input.setattribute("type","number"); input.onkeydown = function (e) { var oevent = e || event; if (oevent.keycode == '13') { var val = parseint(oevent.target.value); if (typeof val === 'number' && val <= that.pagetotal && val>0) { that.curpage = val; that.getpage(that.curpage); }else{ alert("请输入正确的页数 !") } that.init(); } }; li.appendchild(input); var span2 = document.createelement('span'); span2.innerhtml = '页'; li.appendchild(span2); this.ul.appendchild(li); }, //是否显示总页数,每页个数,数据 showpagetotal: function showpagetotal() { var that = this; var li = document.createelement('li'); li.innerhtml = '共 ' + that.pagetotal + ' 页'; li.classname = 'totalpage'; this.ul.appendchild(li); // var li2 = document.createelement('li'); // li2.innerhtml = '每页 ' + that.pageamount + ' 条'; // li2.classname = 'totalpage'; // this.ul.appendchild(li2); // var li3 = document.createelement('li'); // li3.innerhtml = '合计 ' + that.datatotal + ' 条数据'; // li3.classname = 'totalpage'; // this.ul.appendchild(li3); } };