var Paging = (function() { function Paging(elementName, options) { this.elementName = elementName; this.options = options; options.nowPage = options.nowPage >= 1 ? options.nowPage : 1; options.pageNum = options.pageNum > 0 ? options.pageNum : 0; options.canJump = options.canJump || 0; options.showOne = options.showOne || 0; options.buttonNum = (options.buttonNum >= 5 ? options.buttonNum : 5) || 7; this.nowPage = options.nowPage > options.pageNum ? options.pageNum : options.nowPage; this.pageNum = options.pageNum < 0 ? 0 : options.pageNum; this.canJump = options.canJump; this.showOne = options.showOne; this.buttonNum = options.buttonNum; this.callback = options.callback; this.element = document.getElementById(elementName); this.init(); } Paging.prototype.init = function() { this.createHtml(); }; Paging.prototype.createHtml = function() { var _this = this; var content = []; if (this.pageNum <= 0) { return ''; } if (!this.showOne && this.pageNum === 1) { this.element.innerHTML = ''; return ''; } content.push(""); this.element.innerHTML = content.join(''); setTimeout(function() { _this.disabled(); _this.bindClickEvent(); }, 20); }; Paging.prototype.bindClickEvent = function() { var _this = this; var liList = this.element.children[0].children; var _loop_1 = function(i) { liList[i].removeEventListener('click', function() { _this.clickEvent(liList[i]); }); }; for (var i = 0; i < liList.length; i++) { _loop_1(i); } var _loop_2 = function(i) { liList[i].addEventListener('click', function() { _this.clickEvent(liList[i]); }); }; for (var i = 0; i < liList.length; i++) { _loop_2(i); } }; Paging.prototype.clickEvent = function(li) { var cla = li.className; var num = parseInt(li.innerHTML); var nowPage = this.nowPage; if (li.className.indexOf('xl-disabled') !== -1 || cla === 'xl-jumpText') { return ''; } if (cla === 'xl-prevPage') { if (nowPage >= 1) { this.nowPage -= 1; } } else if (cla === 'xl-nextPage') { if (nowPage < this.pageNum) { this.nowPage += 1; } } else if (cla === 'xl-jumpButton') { var el = document.getElementById('xlJumpNum'); if (Number(el.value) > this.pageNum) { this.nowPage = this.pageNum; } else if (Number(el.value) <= 0) { this.nowPage = 1; } else { this.nowPage = Number(el.value); } } else { this.nowPage = num; } this.createHtml(); if (this.callback) { this.callback(this.nowPage); } }; Paging.prototype.disabled = function() { var nowPage = this.nowPage; var pageNum = this.pageNum; var liList = this.element.children[0].children; if (nowPage === 1) { for (var i = 0; i < liList.length; i++) { if (liList[i].className.indexOf('xl-prevPage') !== -1) { liList[i].setAttribute('class', liList[i].getAttribute('class').concat(' xl-disabled')); } } } else if (nowPage === pageNum) { for (var i = 0; i < liList.length; i++) { if (liList[i].className.indexOf('xl-nextPage') !== -1) { liList[i].setAttribute('class', liList[i].getAttribute('class').concat(' xl-disabled')); } } } }; return Paging; }());