肥宅自学平台_人人成为技术开发者

肥宅人只等待您,联系我们吧,曾经的巅峰是否能回来?我们正在用心服务!

jQuery如何分页插件

 更新时间:2024-04-24 16:28:07   作者:肥宅-季波   我要评论(0)  

         jQuery监听用JavaScript分布函数来制作分页链接,可以省下很多html代码流量呢
  1. (function($) {
  2. $.fn.pagination = function(pagecount, page, surl) {
  3. var $box = $(this).empty();
  4. var shtml = ''
  5. if (pagecount <= 1) {
  6. $box.css({
  7. 'height': 4,
  8. 'padding': 0
  9. });
  10. return $box
  11. }
  12. if (page == 1) shtml += '<a href="#" target="_self">«</a>';
  13. else shtml += '<a href="' + surl.replace("$", (page - 1)) + '" target="_self">«</a>';
  14. if (pagecount < 11) {
  15. for (var i = 1; i <= pagecount; i++) {
  16. if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>';
  17. else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>'
  18. }
  19. } else {
  20. if (page <= 10) {
  21. for (var i = 1; i <= 10; i++) {
  22. if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>';
  23. else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>'
  24. }
  25. } else if (pagecount - page < 10) {
  26. for (var i = pagecount - 9; i <= pagecount; i++) {
  27. if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>';
  28. else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>'
  29. }
  30. } else {
  31. for (var i = page - 5; i < page + 5; i++) {
  32. if (i == page) shtml += '<a href="' + surl.replace("$", i) + '" class="c" target="_self">' + i + '</a>';
  33. else shtml += '<a href="' + surl.replace("$", i) + '" target="_self">' + i + '</a>'
  34. }
  35. }
  36. }
  37. if (page == pagecount) shtml += '<a href="#">»</a>';
  38. else shtml += '<a target="_self" href="' + surl.replace("$", (page + 1)) + '">»</a>';
  39. if (pagecount > 10) {
  40. shtml += '<span>跳转到 </span>';
  41. shtml += '<input type="text" size="2" maxlength="4" value="' + page + '" />';
  42. shtml += '<span> 页</span>'
  43. }
  44. $box.html(shtml).find('input').change(function() {
  45. var p = $(this).val();
  46. window.location.href = surl.replace("$", p)
  47. });
  48. return $box
  49. }
  50. })(jquery);
之后只要这么引用它就好了:
  1. $(function(){$('#page').pagination(100,1,'aaa.htm?page=
  2. )})
"小礼物走一走,来肥宅自学平台支持我"
评论区

评论

共条评论
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~
客服中心在线客服
全心全意为平台用户服务
Copyright © 2017-2023 自学平台网站地图:去查看>
  • 肥宅人自己的自学平台
  • 人人都能成为平台讲师
  • 贡献你的力量壮大肥宅自学平台
  • 将自己的能力变现
  • 实现人生的第二职业
网址收藏平台安卓APP
微信公众号微信公众号

本站部分图片或者资源来自程序自动采集或卖家(商家)发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!

肥宅自学教程网是一个主打IT视频教程、自媒体运行、摄影剪辑等内容的资源学习交流平台。