我以前寫的一個jQuery分頁插件
用JavaScript分布函數來制作分頁鏈接,可以省下很多html代碼流量呢!看看
(function($){
$.fn.pagination=function(pagecount,page,surl){
var $box=$(this).empty();var shtml=''
if(pagecount<=1){$box.css({'height':4,'padding':0});return $box;}
//$box.css({'padding':'6px 0 6px 6px','height':'20px'});
if(page==1)shtml+='<a href="#" target="_self">«</a>';else shtml+='<a href="'+surl.replace("$",(page-1))+'" target="_self">«</a>';
if(pagecount<11){for(var i=1;i<=pagecount;i++){if(i==page)shtml+='<a href="'+surl.replace("$",i)+'" class="c" target="_self">'+i+'</a>';else shtml+='<a href="'+surl.replace("$",i)+'" target="_self">'+i+'</a>';}}
else{if(page<=10){for(var i=1;i<=10;i++){if(i==page)shtml+='<a href="'+surl.replace("$",i)+'" class="c" target="_self">'+i+'</a>';else shtml+='<a href="'+surl.replace("$",i)+'" target="_self">'+i+'</a>';}}else if(pagecount-page<10){for(var i=pagecount-9;i<=pagecount;i++){if(i==page)shtml+='<a href="'+surl.replace("$",i)+'" class="c" target="_self">'+i+'</a>';else shtml+='<a href="'+surl.replace("$",i)+'" target="_self">'+i+'</a>';}}else{for(var i=page-5;i<page+5;i++){if(i==page)shtml+='<a href="'+surl.replace("$",i)+'" class="c" target="_self">'+i+'</a>';else shtml+='<a href="'+surl.replace("$",i)+'" target="_self">'+i+'</a>';}}}
if(page==pagecount)shtml+='<a href="#">»</a>';else shtml+='<a target="_self" href="'+surl.replace("$",(page+1))+'">»</a>';
if(pagecount>10){shtml+='<span>跳轉到 </span>';shtml+='<input type="text" size="2" maxlength="4" value="'+page+'" />';
shtml+='<span> 頁</span>';
}
$box.html(shtml).find('input').change(function(){var p=$(this).val();window.location.href=surl.replace("$",p);});
return $box;
}
})(jquery);
之后只要這么引用它就好了:$(function(){$('#page').pagination(100,1,'aaa.htm?page=$')})
您可能感興趣的文章:
jquery插件開發注意事項小結
jQuery圖片輪換插件 jQuery Dynamic Slideshow
jQuery Pagination Ajax分頁插件(分頁切換時無刷新與延遲)中文翻譯版
基于jquery的simpleValidate簡易驗證插件
使用jQuery.fn自定義jQuery翻頁插件
自己動手制作jquery插件之自動添加刪除行功能介紹
jquery easyui 分頁的使用方法
基于jQuery的表格操作插件
jQuery版仿Path菜單效果
jQuery條目展示插件 Easy Paginate