First look at the effect chart:
Simple Paging JS code:
1, Effect Description:
jquery plug-ins to display without paging
JQuery Paging Plugin--jquery.page.js usage is very simple, the effect is very good
2. Calling method:
$ (". Tcdpagecode"). Createpage ({
pagecount:10,
current:1,
backfn:function (p) {
//Click callback method, p is current page number
}
});
PageCount: Total Pages
3, JS package code
Paging plugin/** ch **/(function ($) {var ms = {Init:function (Obj,args) {return (function () {ms.fillhtml (obj
, args);
Ms.bindevent (Obj,args);
})();
},//Populate HTML Fillhtml:function (Obj,args) {return (function () {obj.empty ());
Previous page if (Args.current > 1) {obj.append (' <a href= ' javascript:; "class=" PrevPage "> Prev </a>");
}else{obj.remove ('. PrevPage ');
Obj.append (' <span class= ' disabled ' > Prev </span> '); //Middle page number if (args.current!= 1 && args.current >= 4 && args.pagecount!= 4) {obj.append (
' <a href= ' javascript:; "class=" Tcdnumber "> ' +1+ ' </a>"); } if (Args.current-2 > 2 && args.current <= args.pagecount && args.pagecount > 5) {obj.
Append (' <span>...</span> ');
var start = Args.current-2,end = args.current+2; if (Start > 1 && args.current < 4) | | Args.current = = 1) {End++;
} if (Args.current > Args.pagecount-4 && args.current >= args.pagecount) {start--; for (; Start <= end; start++) {if (Start <= args.pagecount && start >= 1) {if (Start!=
Args.current) {obj.append (' <a href= "javascript:;" class= "Tcdnumber" > "+ start + ' </a>");
}else{obj.append (' <span class= ' current ' > ' + start + ' </span> '); }} if (Args.current + 2 < args.pagecount-1 && args.current >= 1 && Args.pagecoun
T > 5) {obj.append (' <span>...</span> ');
} if (args.current!= args.pagecount && args.current < args.pagecount-2 && Args.pagecount!= 4) {
Obj.append (' <a href= "javascript:;" class= "Tcdnumber" > ' +args.pagecount+ ' </a> "); //Next if (Args.current < Args.pagecount) {obj.append (' <a href= "javascript:;" class= "NextPage" > Next
Page </a> '); }else{obj.remove ('. NextPage ');
Obj.append (' <span class= "disabled" > next page </span> ");
}
})();
},//Binding event Bindevent:function (Obj,args) {return (function () {Obj.on ("click", "A.tcdnumber", function () {
var current = parseint ($ (this). text ());
Ms.fillhtml (obj,{"current": Current, "PageCount": Args.pagecount});
if (typeof (ARGS.BACKFN) = = "function") {ARGS.BACKFN (current);
}
});
Previous page Obj.on ("click", "A.prevpage", function () {var current = parseint (Obj.children ("Span.current"). Text ());
Ms.fillhtml (obj,{"current": Current-1, "PageCount": Args.pagecount});
if (typeof (ARGS.BACKFN) = = "function") {ARGS.BACKFN (current-1);
}
});
Next page Obj.on ("click", "A.nextpage", function () {var current = parseint (Obj.children ("Span.current"). Text ());
Ms.fillhtml (obj,{"current": current+1, "PageCount": Args.pagecount}); if (typeof (ARGS.BACKFN) = = "function") {ARGS.BACKFN (current+1);
}
});
})(); } $.fn.createpage = function (options) {var args = $.extend ({pagecount:10, current:1, Backfn:fu
Nction () {}},options);
Ms.init (This,args); }) (JQuery);
4, using demo:
The above is the entire content of this article, I hope to learn JavaScript to help you.