$.setpage = function pagination(option) { var defaults = { spagecount: 0, scurrentpage: 1, stotalrecord: 0, divdom: null, groups:5,//显示数字个数 first : '首页', last : '尾页', prev : '上一页', next: '下一页', prevtemp : "{1}", firsttemp : "{0}", pagetemp : "{0}", curpagetemp : "{0}", lasttemp : "{1}", nexttemp : "{0}" } var emt = {}; var setting = $.extend(emt, defaults, option); var view = [], dict = {}; var pages = setting.spagecount | 0; var curr = (setting.scurrentpage | 0) || 1; var groups = setting.groups;//显示5个 var first = setting.first; var last = setting.last; var prev = setting.prev; var next = setting.next; var stotalrecord = setting.stotalrecord; var prevtemp = setting.prevtemp; var firsttemp = setting.firsttemp; var pagetemp = setting.pagetemp; var curpagetemp = setting.curpagetemp; var lasttemp = setting.lasttemp; var nexttemp = setting.nexttemp; var divdom = setting.divdom; var shref = setting.shref; //清空控件 $(divdom).empty(); if (stotalrecord == 0) { return ''; } if (pages <= 1) { view.push('
共' + stotalrecord + '条记录'); $(divdom).html(view.join('')); return ''; } if (groups > pages) { groups = pages; } //计算当前组 dict.index = math.ceil((curr + ((groups > 1 && groups !== pages) ? 1 : 0)) / (groups === 0 ? 1 : groups)); //当前组非首组,则输出首页 if (dict.index > 1 && first && groups !== 0) { //view.push('' + first + '…'); view.push(firsttemp.format3(first,shref) + "…"); } else { view.push(firsttemp.format3(first,shref)); } //当前页非首页,则输出上一页 if (curr > 1 && prev) { //view.push('' + prev + ''); view.push(prevtemp.format3(curr - 1, prev,shref)); } //输出当前页组 dict.poor = math.floor((groups - 1) / 2); dict.start = dict.index > 1 ? curr - dict.poor : 1; dict.end = dict.index > 1 ? (function () { var max = curr + (groups - dict.poor - 1); return max > pages ? pages : max; }()) : groups; if (dict.end - dict.start < groups - 1) { //最后一组状态 dict.start = dict.end - groups + 1; } for (; dict.start <= dict.end; dict.start++) { if (dict.start === curr) { //view.push('' + dict.start + ''); view.push(curpagetemp.format3(dict.start,shref)); } else { //view.push('' + dict.start + ''); view.push(pagetemp.format3(dict.start,shref)); } } //当前页不为尾页时,输出下一页 dict.flow = !prev && groups === 0; if (curr !== pages && next || dict.flow) { view.push((function () { return (dict.flow && curr === pages) ? nexttemp.format3(next, "", shref) : nexttemp.format3(next, curr + 1,shref) }())); } //总页数大于连续分页数,且当前组最大页小于总页,输出尾页 if (pages > groups && dict.end < pages && last && groups !== 0) { //view.push('…' + last + ''); view.push("…" + lasttemp.format3(pages, last,shref)); } else { view.push(lasttemp.format3(pages, last,shref)); } //view.push('到第页 '); ////添加事件 $(divdom).html(view.join('')); $(divdom).find("a").on("click", function () { var that = this.outerhtml; var curr = $(that).attr("data-page"); //修改(上下首末页) //initgrid(curr, queryobj.l_stype); $("#test").val(curr);// = curr; //可以不要了 return curr; }); $(divdom).find("input:eq(1)").on("click", function () { // var that = $(divdom).find("a:last").attr("data-page"); var curr = $(divdom).find("input")[0].value.replace(/\s|\d/g, '') | 0; if (curr == 0 || curr == "") { curr = 1; } if (curr > spagecount) { curr = spagecount; } //initgrid(curr, queryobj.l_stype) return; }); };