$.fn.mypagination = function(totalproperty,opts){ opts = $.extend({ perpage:pagesize, callback:function(){ } },opts||{}); return this.each(function(){ function numpages(){ return math.ceil(totalproperty/opts.perpage); } function selectpage(page){ if(isnan(page)){ alert("请正确输入分页数字!!"); return false; } var re = /^[1-9]+[0-9]*]*$/; if(!re.test(page+2)){ alert("请输入整数!!!"); return false; } return function(){ currpage = page; if (page<0) currpage = 0; if (page>=numpages()) currpage = numpages()-1; render(); opts.callback(currpage+1); } } function render(){ if(numpages()!=0){ var html= '
'+numpages()+'页 这是第['+(currpage+1)+']页' ; if(currpage > 0){ html=html+' 首页' +' 上一页'; }else{ html=html+'首页' +'上一页'; } if (currpage < numpages()-1){ html=html+' 下一页' +'尾页'; }else{ html=html+'下一页' +' 尾页'; } html=html+'
'; }else { html="暂无记录"; } panel.empty(); panel.append(html); $(".page-first",panel) .bind('click',selectpage(0)); $(".page-prev",panel) .bind('click',selectpage(currpage-1)); $(".page-next",panel) .bind('click',selectpage(currpage+1)); $(".page-last",panel) .bind('click',selectpage(numpages()-1)); } var currpage = 0; var panel = $(this); render(); }); }