首页 >web前端 >js教程 >分享一个Query分页插件代码

分享一个Query分页插件代码

零下一度
零下一度原创
2017-06-17 15:33:171159浏览

JavaScript分布函数制作分页链接,可以省下很多html代码流量呢!看看

(function($){
$.fn.pagination=function(pagecount,page,surl){
var $box=$(this).empty();var shtml=''
if(pagecount<=1){$box.css({&#39;height&#39;:4,&#39;padding&#39;:0});return $box;}
//$box.css({&#39;padding&#39;:&#39;6px 0 6px 6px&#39;,&#39;height&#39;:&#39;20px&#39;});
if(page==1)shtml+=&#39;<a href="#" target="_self">&laquo;</a>&#39;;else shtml+=&#39;<a href="&#39;+surl.replace("$",(page-1))+&#39;" target="_self">&laquo;</a>&#39;;
if(pagecount<11){for(var i=1;i<=pagecount;i++){if(i==page)shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" class="c" target="_self">&#39;+i+&#39;</a>&#39;;else shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" target="_self">&#39;+i+&#39;</a>&#39;;}}
else{if(page<=10){for(var i=1;i<=10;i++){if(i==page)shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" class="c" target="_self">&#39;+i+&#39;</a>&#39;;else shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" target="_self">&#39;+i+&#39;</a>&#39;;}}else if(pagecount-page<10){for(var i=pagecount-9;i<=pagecount;i++){if(i==page)shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" class="c" target="_self">&#39;+i+&#39;</a>&#39;;else shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" target="_self">&#39;+i+&#39;</a>&#39;;}}else{for(var i=page-5;i<page+5;i++){if(i==page)shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" class="c" target="_self">&#39;+i+&#39;</a>&#39;;else shtml+=&#39;<a href="&#39;+surl.replace("$",i)+&#39;" target="_self">&#39;+i+&#39;</a>&#39;;}}}
if(page==pagecount)shtml+=&#39;<a href="#">&raquo;</a>&#39;;else shtml+=&#39;<a target="_self" href="&#39;+surl.replace("$",(page+1))+&#39;">&raquo;</a>&#39;;
if(pagecount>10){shtml+=&#39;<span>跳转到 </span>&#39;;shtml+=&#39;<input type="text" size="2" maxlength="4" value="&#39;+page+&#39;" />&#39;;
shtml+=&#39;<span> 页</span>&#39;;
}
$box.html(shtml).find(&#39;input&#39;).change(function(){var p=$(this).val();window.location.href=surl.replace("$",p);});
return $box;
}
})(jquery);

之后只要这么引用它就好了:

$(function(){$(&#39;#page&#39;).pagination(100,1,&#39;aaa.htm?page=$&#39;)})

以上是分享一个Query分页插件代码的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn