$.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 = '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
|
html = html + '<tbody>';
|
html = html + '<tr><td align="center" class="pn-sp">'
|
//html = html + '每页 ' + opts.perPage + ' 条 ';
|
html = html + '<input class="page-first" type="button" value="首 页" style="font-size:12px;border:1px solid #CCCCCC;height:25px;line-height:25px;margin:0 2px;background:#FFFFFF;"/>';
|
html = html + '<input class="page-prev" type="button" value="上一页" style="font-size:12px;border:1px solid #CCCCCC;height:25px;line-height:25px;margin:0 2px;background:#FFFFFF;"/>';
|
html = html + '<input class="page-next" type="button" value="下一页" style="font-size:12px;border:1px solid #CCCCCC;height:25px;line-height:25px;margin:0 2px;background:#FFFFFF;"/>';
|
html = html + '<input class="page-last" type="button" value="尾 页" style="font-size:12px;border:1px solid #CCCCCC;height:25px;line-height:25px;margin:0 2px;background:#FFFFFF;"/> ';
|
html = html + '<input class="page-first" type="button" value="共' + opts.recordCount + '条" style="font-size:12px;border:1px solid #CCCCCC;height:25px;line-height:25px;margin:0 2px;background:#FFFFFF;"/> ';
|
//html = html + '<input type="text" class="turn-page-input" maxlength="10" value="'+currPage+'" size="2"/> ';
|
//html = html + '<input type="button" class="turn-page-btn" style="font-size:12px;border:1px solid #CCCCCC;height:25px;line-height:25px;margin:0 2px;background:#FFFFFF;" value="跳转"> ';
|
//html = html + '当前 ' + currPage + '/' + opts.totalPage + ' 页 ';
|
html = html + '</td></tr></tbody></table>';
|
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);
|
}
|
render();
|
});
|
};
|