(function($){
var zp = {
init:function(obj,pageinit){
return (function(){
zp.addhtml(obj,pageinit);
zp.bindevent(obj,pageinit);
}());
},
addhtml:function(obj,pageinit){
return (function(){
obj.empty();
/*上一页*/
if (pageinit.current > 1) {
obj.append('上一页');
} else{
obj.remove('.prevpage');
obj.append('上一页');
}
// /*中间页*/
if (pageinit.current >4 && pageinit.pagenum > 4) {
obj.append(''+1+'');
obj.append(''+2+'');
obj.append('...');
}
if (pageinit.current >4 && pageinit.current <= pageinit.pagenum-5) {
var start = pageinit.current - 2,end = pageinit.current + 2;
}else if(pageinit.current >4 && pageinit.current > pageinit.pagenum-5){
var start = pageinit.pagenum - 4,end = pageinit.pagenum;
}else{
var start = 1,end = 9;
}
for (;start <= end;start++) {
if (start <= pageinit.pagenum && start >=1) {
if (start == pageinit.current) {
obj.append(''+ start +'');
} else if(start == pageinit.current+1){
obj.append(''+ start +'');
}else{
obj.append(''+ start +'');
}
}
}
if (end < pageinit.pagenum) {
obj.append('...');
}
/*下一页*/
if (pageinit.current >= pageinit.pagenum) {
obj.remove('.nextbtn');
obj.append('下一页');
} else{
obj.append('下一页');
}
/*尾部*/
// obj.append(''+'共'+''+pageinit.pagenum+''+'页,'+'');
// obj.append(''+'到第'+''+'页'+'');
// obj.append(''+'确定'+'');
}());
},
bindevent:function(obj,pageinit){
return (function(){
obj.on("click","a.prebtn",function(){
var cur = parseint(obj.children("span.current").text());
var current = $.extend(pageinit, {"current":cur-1});
zp.addhtml(obj,current);
if (typeof(pageinit.backfun)=="function") {
pageinit.backfun(current);
}
});
obj.on("click","a.zxfpagenum",function(){
var cur = parseint($(this).text());
var current = $.extend(pageinit, {"current":cur});
zp.addhtml(obj,current);
if (typeof(pageinit.backfun)=="function") {
pageinit.backfun(current);
}
});
obj.on("click","a.nextbtn",function(){
var cur = parseint(obj.children("span.current").text());
var current = $.extend(pageinit, {"current":cur+1});
zp.addhtml(obj,current);
if (typeof(pageinit.backfun)=="function") {
pageinit.backfun(current);
}
});
obj.on("click","span.zxfokbtn",function(){
var cur = parseint($("input.zxfinput").val());
var current = $.extend(pageinit, {"current":cur});
zp.addhtml(obj,{"current":cur,"pagenum":pageinit.pagenum});
if (typeof(pageinit.backfun)=="function") {
pageinit.backfun(current);
}
});
}());
}
}
$.fn.createpage = function(options){
var pageinit = $.extend({
pagenum : 15,
current : 1,
backfun : function(){}
},options);
zp.init(this,pageinit);
}
}(jquery));