(function ($) {
var ms = {
init: function (obj, args) { return (function () { ms.fillhtml(obj, args); ms.bindevent(obj, args); })(); }, fillhtml: function (obj, args) {args.current = number(args.current)
return (function () {
obj.empty();
if (args.current > 1) { obj.append('上一页'); } else { obj.remove('.prevpage'); obj.append('上一页'); }
if (args.current != 1 && args.current >= 4 && args.pagecount != 4) { obj.append('' + 1 + ''); }
if (args.current - 2 > 2 && args.current <= args.pagecount && args.pagecount > 5) { obj.append('...'); }
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('' + start + ''); } else { obj.append('' + start + ''); } } }
if (args.current + 2 < args.pagecount - 1 && args.current >= 1 && args.pagecount > 5) { obj.append('...'); }
if (args.current != args.pagecount && args.current < args.pagecount - 2 && args.pagecount != 4) { obj.append('' + args.pagecount + ''); }
if (args.current < args.pagecount) { obj.append('下一页'); } else { obj.remove('.nextpage'); obj.append('下一页'); }
obj.append('共' + args.pagecount + '页'); if (args.turndown == 'true') { obj.append('到第页确定'); }
})();
}, 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, "turndown": args.turndown }); if (typeof (args.backfn) == "function") { args.backfn(current); } }); obj.on("click", "a.prevpage", function () { var current = parseint(obj.children("span.current").text()); ms.fillhtml(obj, { "current": current - 1, "pagecount": args.pagecount, "turndown": args.turndown }); if (typeof (args.backfn) == "function") { args.backfn(current - 1); } }); obj.on("click", "a.nextpage", function () { var current = parseint(obj.children("span.current").text()); ms.fillhtml(obj, { "current": current + 1, "pagecount": args.pagecount, "turndown": args.turndown }); if (typeof (args.backfn) == "function") { args.backfn(current + 1); } }); obj.on("click", "a.turndown", function () {
var page = $("span.countye input").val(); if (page > args.pagecount) { alert("您的输入有误,请重新输入!"); }
ms.fillhtml(obj, { "current": page, "pagecount": args.pagecount, "turndown": args.turndown });
});
})();
}
}
$.fn.createpage = function (options) { var args = $.extend({ pagecount: 10, current: 1, turndown: true, backfn: function () { } }, options); ms.init(this, args); }
})(jquery);