$.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= '
'; }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(); }); }