国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

使用JQuery實現的分頁插件分享

2024-05-06 16:24:56
字體:
來源:轉載
供稿:網友

本文給大家總結了幾種使用jQuery實現的分頁插件,效果非常不錯,有需要的小伙伴可以參考下。

一個簡單的jQuery分頁插件,兼容AMD規范和requireJS.

 

 
  1. /** 
  2. * jQuery分頁插件 
  3. * */ 
  4. ;(function (factory) { 
  5. if (typeof define === "function" && define.amd) { 
  6. // AMD模式 
  7. define([ "jquery" ], factory); 
  8. else { 
  9. // 全局模式 
  10. factory(jQuery); 
  11. }(function ($) { 
  12.  
  13. //定義MyPagePlugin的構造函數 
  14. MyPagePlugin = function(ele, option) { 
  15. // this.viewHtml="<nav><ul class='pagination'><li><a id='firstPageli'>«</a></li><li><a id='prevPageli'>‹</a></li><li class='active'><a>第<span id='curPageNoSpan'></span>頁,共<span id='allPageCountSpan'></span>頁</a></li><li><a id='nextPageli'>›</a></li><li><a id='lastPageli'>»</a></li></ul></nav>"; 
  16. this.viewHtml= "<div class='pageplugin'><a class='first firstPageli'>«</a><a class='previous prevPageli'>‹</a><a class='present'>第<span class='curPageNoSpan'></span>頁,共<span class='allPageCountSpan'></span>頁</a><a class='next nextPageli'>›</a><a class='last lastPageli'>»</a></div>" 
  17.  
  18. this.$element = ele; 
  19. /**參數:page:當前頁,pageCount:總共頁數,onPaged回調函數,回調函數會傳入頁數*/ 
  20. this.defaults = { 
  21. page:1, 
  22. pageCount:1, 
  23. onPaged:function(pageNo){} 
  24. }; 
  25. this.options = $.extend({}, this.defaults, option); 
  26.  
  27. //定義MyPagePlugin的方法 
  28. MyPagePlugin.prototype = { 
  29. initPlugin:function(){ 
  30. this.$element.empty(); 
  31. this.$element.append(this.viewHtml); 
  32. this.options.onPaged(this.options.page);//初始化 
  33. this.$element.find(".curPageNoSpan").text(this.options.page); 
  34. this.$element.find(".curPageNoSpan").data("options",this.options); 
  35. this.$element.find(".allPageCountSpan").text(this.options.pageCount); 
  36. this.$element.find(".firstPageli").on("click",function(e){ 
  37.  
  38. var curNo=$(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(); 
  39. curNo=parseInt(curNo); 
  40. if(curNo==1){ 
  41. return false
  42. }else
  43.  
  44. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").data("options").onPaged(1); 
  45. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(1); 
  46. return false
  47. }); 
  48. this.$element.find(".prevPageli").on("click",function(e){ 
  49. var curNo=$(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(); 
  50. curNo=parseInt(curNo); 
  51. if(curNo==1){ 
  52. return false
  53. }else
  54. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").data("options").onPaged(curNo-1); 
  55. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(curNo-1); 
  56. return false
  57. }); 
  58. this.$element.find(".nextPageli").on("click",function(e){ 
  59. var curNo=$(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(); 
  60. curNo=parseInt(curNo); 
  61. var pageCount=$(e.currentTarget).parent("div.pageplugin").find(".allPageCountSpan").text(); 
  62. pageCount=parseInt(pageCount); 
  63. if(curNo==pageCount){ 
  64. return false
  65. }else
  66. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").data("options").onPaged(curNo+1); 
  67. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(curNo+1); 
  68. return false
  69. }); 
  70. this.$element.find(".lastPageli").on("click",function(e){ 
  71. var curNo=$(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(); 
  72. curNo=parseInt(curNo); 
  73. var pageCount=$(e.currentTarget).parent("div.pageplugin").find(".allPageCountSpan").text(); 
  74. pageCount=parseInt(pageCount); 
  75. if(curNo==pageCount){ 
  76. return false
  77. }else
  78. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").data("options").onPaged(pageCount); 
  79. $(e.currentTarget).parent("div.pageplugin").find(".curPageNoSpan").text(pageCount); 
  80. return false
  81. }); 
  82.  
  83.  
  84.  
  85. $.fn.pagePlugin = function (option) { 
  86. var pagePlugin=new MyPagePlugin(this,option); 
  87. pagePlugin.initPlugin(); 
  88. }; 
  89. })); 

CSS

 

 
  1. .pageplugin { 
  2. display: inline-block; 
  3. border: 1px solid #CDCDCD; 
  4. border-radius: 3px; } 
  5.  
  6. .pageplugin a { 
  7. cursor: pointer; 
  8. display: block; 
  9. float: left; 
  10. width: 20px; 
  11. height: 20px; 
  12. outline: none; 
  13. border-right: 1px solid #CDCDCD; 
  14. border-left: 1px solid #CDCDCD; 
  15. color: #767676; 
  16. vertical-align: middle; 
  17. text-align: center; 
  18. text-decoration: none; 
  19. font-weight: bold; 
  20. font-size: 16px; 
  21. font-family: Times, 'Times New Roman', Georgia, Palatino; 
  22. background-color: #f7f7f7; 
  23. /* ATTN: need a better font stack  
  24. background-color: #f7f7f7; 
  25. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f3f3f3), color-stop(100%, lightgrey)); 
  26. background-image: -webkit-linear-gradient(#f3f3f3, lightgrey); 
  27. background-image: linear-gradient(#f3f3f3, lightgrey); */
  28. .pageplugin a:hover, .pageplugin a:focus, .pageplugin a:active { 
  29. color:#0099CC; 
  30. background-color: #cecece; 
  31. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #e4e4e4), color-stop(100%, #cecece)); 
  32. background-image: -webkit-linear-gradient(#e4e4e4, #cecece); 
  33. background-image: linear-gradient(#e4e4e4, #cecece); } 
  34. .pageplugin a.disabled, .pageplugin a.disabled:hover, .pageplugin a.disabled:focus, .pageplugin a.disabled:active { 
  35. background-color: #f3f3f3; 
  36. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f3f3f3), color-stop(100%, lightgrey)); 
  37. background-image: -webkit-linear-gradient(#f3f3f3, lightgrey); 
  38. background-image: linear-gradient(#f3f3f3, lightgrey); 
  39. color: #A8A8A8; 
  40. cursor: default; } 
  41.  
  42. .pageplugin a:first-child { 
  43. border: none; 
  44. border-radius: 2px 0 0 2px; } 
  45.  
  46. .pageplugin a:last-child { 
  47. border: none; 
  48. border-radius: 0 2px 2px 0; } 
  49.  
  50. .pageplugin .present { 
  51. float: left; 
  52. margin: 0; 
  53. padding: 0; 
  54. width: 120px; 
  55. height: 20px; 
  56. outline: none; 
  57. border: none; 
  58. vertical-align: middle; 
  59. text-align: center; } 

jquery分頁插件cypager

cypager是網友分享到JquerySchool網站上的一款作品,非常實用,經過測試,插件兼容 IE8+,Chrome,Firefox 瀏覽器,核心文件僅 5KB。。。

調用方式

由于是 jquery插件,所以在引人 cypager.min.js 之前,要引人 jquery.min.js 本人使用的是 1.7.2 版本的,低版本的沒試過。

引入css :

引人js :

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 全椒县| 简阳市| 岑巩县| 三明市| 河北省| 武威市| 左权县| 佛教| 中超| 东莞市| 平乡县| 贵州省| 巴彦淖尔市| 鹤山市| 成武县| 三江| 南通市| 稻城县| 天镇县| 增城市| 叙永县| 红河县| 清远市| 龙岩市| 乐清市| 磴口县| 普洱| 无为县| 称多县| 鄄城县| 卓尼县| 连平县| 葫芦岛市| 怀远县| 金阳县| 资中县| 南靖县| 巩义市| 沙河市| 白银市| 九江县|