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">&laquo;</a>';else shtml+='<a href="'+surl.replace("$",(page-1))+'" target="_self">&laquo;</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="#">&raquo;</a>';else shtml+='<a target="_self" href="'+surl.replace("$",(page+1))+'">&raquo;</a>';
if(pagecount>10){shtml+='<span>跳转到&nbsp;</span>';shtml+='<input type="text" size="2" maxlength="4" value="'+page+'" />';
shtml+='<span>&nbsp;页</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分页插件代码的详细内容,更多请关注Work网其它相关文章!

09-16 15:18