前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)
html
分页
paging.js
(function($, window, document, undefined) {//定义分页类function Paging2(element, options) {this.element &#61; element;//传入形参this.options &#61; {pageNo: options.pageNo||1,totalPage: options.totalPage,totalSize:options.totalSize,callback:options.callback};//根据形参初始化分页html和css代码this.init();}//对Paging的实例对象添加公共的属性和方法Paging2.prototype &#61; {constructor: Paging2,init: function() {this.creatHtml();this.bindEvent();},creatHtml: function() {var me &#61; this;var content &#61; "";var current &#61; me.options.pageNo;var total &#61; me.options.totalPage;var totalNum &#61; me.options.totalSize;content &#43;&#61; " 共"&#43;totalNum&#43;"条 ";content &#43;&#61; "首页上一页";//总页数大于6时候if(total > 6) {//当前页数小于5时显示省略号if(current <5) {for(var i &#61; 1; i <6; i&#43;&#43;) {if(current &#61;&#61; i) {content &#43;&#61; "" &#43; i &#43; "";} else {content &#43;&#61; "" &#43; i &#43; "";}}content &#43;&#61; ". . .";content &#43;&#61; ""&#43;total&#43;"";} else {//判断页码在末尾的时候if(current " &#43; i &#43; "";} else {content &#43;&#61; "" &#43; i &#43; "";}}content &#43;&#61; ". . .";content &#43;&#61; ""&#43;total&#43;"";//页码在中间部分时候 } else {content &#43;&#61; "1";content &#43;&#61; ". . .";for(var i &#61; total - 4; i " &#43; i &#43; "";} else {content &#43;&#61; "" &#43; i &#43; "";}}}}//页面总数小于6的时候} else {for(var i &#61; 1; i " &#43; i &#43; "";} else {content &#43;&#61; "" &#43; i &#43; "";}}}content &#43;&#61; "下一页";content &#43;&#61; "尾页";content &#43;&#61; &#39;到页 确定&#39;;if(total>1){me.element.html(content);}},//添加页面操作事件bindEvent: function() {var me &#61; this;me.element.off(&#39;click&#39;, &#39;a&#39;);me.element.on(&#39;click&#39;, &#39;a&#39;, function() {var num &#61; $(this).html();var id&#61;$(this).attr("id");if(id &#61;&#61; "prePage") {if(me.options.pageNo &#61;&#61; 1) {me.options.pageNo &#61; 1;} else {me.options.pageNo &#61; &#43;me.options.pageNo - 1;}} else if(id &#61;&#61; "nextPage") {if(me.options.pageNo &#61;&#61; me.options.totalPage) {me.options.pageNo &#61; me.options.totalPage} else {me.options.pageNo &#61; &#43;me.options.pageNo &#43; 1;}} else if(id &#61;&#61;"firstPage") {me.options.pageNo &#61; 1;} else if(id &#61;&#61;"lastPage") {me.options.pageNo &#61; me.options.totalPage;}else{me.options.pageNo &#61; &#43;num;}me.creatHtml();if(me.options.callback) {me.options.callback(me.options.pageNo);}});me.element.on(&#39;click&#39;, &#39;.pagegotucur&#39;, function() {var pageval &#61;$(&#39;.pagegotos&#39;).val();if(pageval &#61;&#61; &#39;NaN&#39; || pageval<1 ){return false;}var num &#61; pageval;me.options.pageNo &#61; &#43;num;me.creatHtml();if(me.options.callback) {me.options.callback(me.options.pageNo);}});}};//通过jQuery对象初始化分页对象$.fn.paging2 &#61; function(options) {return new Paging2($(this), options);}
})(jQuery, window, document);
效果