Home > Web Front-end > JS Tutorial > Share a Query paging plug-in code

Share a Query paging plug-in code

零下一度
Release: 2017-06-17 15:33:17
Original
1152 people have browsed it

Use JavaScriptdistributionfunction to make paging links, which can save a lot of html code traffic! Take a look at

(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);
Copy after login

and then just quote it will be fine:

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

The above is the detailed content of Share a Query paging plug-in code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template