$.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);
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 = '
';
panel.empty();
panel.append(html);
if(currPage==1){
$(".page-first",panel).attr("disabled",true);
$(".page-prev",panel).attr("disabled",true);
}else{
$(".page-first",panel).bind('click',_gotopage(1));
$(".page-prev",panel).bind('click',_gotopage(currPage-1));
}
if(currPage==opts.totalPage){
$(".page-next",panel).attr("disabled",true);
$(".page-last",panel).attr("disabled",true);
}else{
$(".page-next",panel).bind('click',_gotopage(currPage+1));
$(".page-last",panel).bind('click',_gotopage(opts.totalPage));
}
$(".turn-page-btn",panel).bind('click',turnPage);
}
*/
function render(){
var html=$('');
if(opts.totalPage>1){
if(currPage>1&&currPage<=opts.totalPage){
html.append($("<").bind('click',_gotopage(currPage-1)));
//$(".page-prev",panel).bind('click',_gotopage(currPage-1));
}else{
html.append("<");//上一页
}
if(currPage<6)
{
for(var i=1;i<=opts.totalPage&&i<=10;i++)
{
if(currPage==i)
{
html.append(""+i+"");
}else{
html.append($(""+i+"").bind('click',_gotopage(i)));
//html.append""+i+"";}
//$(".topage-"+i,panel).bind('click',_gotopage(i));
}
}
if(opts.totalPage>10)
{
html.append("");
}
}else
{
for(var i=currPage-5;i"+i+"");
}else{
html.append($(""+i+"").bind('click',_gotopage(i)));}
}
for(var i=currPage;i<=currPage+4&&i<=opts.totalPage;i++)
{
if(currPage==i)
{
html.append(""+i+"");
}else{
html.append($(""+i+"").bind('click',_gotopage(i)));}
}
if(opts.totalPage>currPage+5)
{
html.append("");
}
}
//html.append(""+currPage+"/"+totalPage+"");
if(currPage>=1&&currPage>").bind('click',_gotopage(currPage+1)));
//$(".page-next",panel).bind('click',_gotopage(currPage+1));
}else{
html.append(">");//下一页
}
panel.empty();
panel.append(html);
}}
render();
});
};