用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=$')})
以上是分享一个Query分页插件代码的详细内容。更多信息请关注PHP中文网其他相关文章!