$.fn.mypagination = function(total,cpage,psize,opts){ opts = $.extend({perPage:psize||1, recordCount:total||0, callback:function(){}}, opts||{}); opts.totalPage = Math.ceil(total/opts.perPage); var totalPanel = this; return this.each(function(){ var currPage; if(cpage>opts.totalPage){ currPage=opts.totalPage; }else{ currPage=cpage; } var panel = $(this); function _gotopage(page){ return function(){ currPage = page; render(); opts.callback(currPage); }; } function turnPage(){ var page = $(".turn-page-input",panel).val(); if(page===""+parseInt(page)){ page = parseInt(page); if(page<=opts.totalPage&&page>=1){ currPage = page; render(); opts.callback(currPage); }else{ alert("请输入正确的页码"); } }else{ alert("请输入正确页码"); } } function render(){ var html = '找到'+opts.recordCount+'个商品'+currPage+'/'+opts.totalPage+''; html += ''; html += ''; totalPanel.each(function() { $(this).empty(); $(this).append(html); if(currPage==1){ $(".page-prev",$(this)).attr("disabled",true); }else{ $(".page-prev",$(this)).bind('click',_gotopage(currPage-1)); } if(total>psize) { if(currPage==opts.totalPage){ $(".page-next",$(this)).attr("disabled",true); }else{ $(".page-next",$(this)).bind('click',_gotopage(currPage+1)); } } }); } render(); }); };