日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

基于jquery的php分页,基于jQuery封装的分页组件

發布時間:2025/4/5 php 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于jquery的php分页,基于jQuery封装的分页组件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:

由于項目需要實現分頁效果,上jQuery插件庫找了下,但是木有找到自己想要的效果,于是自己封裝了個分頁組件。

思路:

主要是初始化時基于原型建立的分頁模板然后綁定動態事件并實現刷新DOM的分頁效果。

1.page.init.css

1 @charset "utf=8"; 2 *{ 3 box-sizing: border-box; 4 padding: 0; 5 margin: 0; 6 } 7 .page{ 8 font-size: 13px; 9 text-align: right;10 }11 .page .page_to{12 display: inline-block;13 max-width: 250px;14 }15 .page .page_to li{16 display: inline-block;17 width: auto;18 height: auto;19 border: 1px solid #ddd;20 padding:5px 10px;21 border-left-width: 0;22 color: #323232;23 cursor: pointer;24 }25 .page .page_to li.page_hide{26 display: none;27 }28 .page .page_to li:hover{29 color: #32C2CD;30 background-color: #f4f4f4;31 border-color: #DDDDDD;32 }33 .page .page_to li:first-child{34 border-left-width: 1px;35 }36 .page .page_jump{37 display: inline-block;38 width: 180px;39 }40 .page .page_jump input.page_jump_input{41 width: 52px;42 height: 28px;43 text-align: center;44 text-decoration: none;45 background-color: #fff;46 border: 1px solid #ddd;47 margin:0 4px;48 }49 .page .page_jump input.page_jump_btn{50 display: inline-block;51 padding: 7px 20px;52 margin-left: 5px;53 font-size: 14px;54 font-weight: 400;55 line-height: 1.42857143;56 text-align: center;57 white-space: nowrap;58 vertical-align: middle;59 -ms-touch-action: manipulation;60 touch-action: manipulation;61 cursor: pointer;62 -webkit-user-select: none;63 -moz-user-select: none;64 -ms-user-select: none;65 user-select: none;66 border: 1px solid transparent;67 border-radius: 4px;68 background-color: #00BB9C;69 color: #FFFFFF;70 font-weight: bold;71 }

2.pageInit.js

1 /** 2 * Created: 2017/6/20. 3 * author: Aaron 4 * address:

5 */ 6 (function($,window,undefined){ 7 8 var curPage='', 9 //跳轉是否有值 10 jumpVal='', 11 //從DOM中重新獲取數據總數/總頁數 12 lists='', 13 totals='', 14 //是否返回值 15 isTrue=false; 16 17 var Page=function(opts){ 18 this.settings= $.extend({},Page.defaults,opts); 19 curPage=this.settings.initPage; 20 totals=this.settings.totalPages; 21 jumpVal=this.settings.inputVal; 22 this.init(); 23 }; 24 25 //默認配置 26 Page.defaults={ 27 container:'.page', 28 setPos:'body', 29 totalPages:null, 30 totalLists:null, 31 initPage:1, 32 inputVal:1, 33 callBack:null 34 }; 35 36 Page.prototype={ 37 init:function(){ 38 this.create(); 39 }, 40 create:function(){ 41 var _template='

'+ 42 ''+ 43 '共'+this.settings.totalLists+'條記錄,'+ 44 '第'+curPage+'/'+ 45 ''+this.settings.totalPages+'頁'+ 46 ''+ 47 ''+ 48 '
  • '+ 49 '
  • 首頁'+ 50 '
  • ? 上一頁'+ 51 '
  • 下一頁 ?'+ 52 '
  • 末頁'+ 53 '
'+ 54 ''+ 55 ''+ 56 '第:頁'+ 57 ''+ 58 ''+ 59 ''; 60 $(this.settings.setPos).append(_template); 61 this.refreshDom(); 62 this.bindEvent(); 63 }, 64 bindEvent:function(){ 65 var _this=this; 66 //跳轉首頁 67 $(this.settings.container).on("click",".page_first",function(){ 68 69 lists=$(_this.settings.container).find(".page_num").text(); 70 totals=$(_this.settings.container).find(".page_size").text(); 71 72 if($.isFunction(_this.settings.callBack)){ 73 curPage=1; 74 isTrue=_this.settings.callBack(1); 75 if(isTrue){ 76 _this.refreshDom(); 77 $(_this.settings.container).find(".page_current").text(1); 78 $(_this.settings.container).find(".page_jump_input").val(curPage); 79 } 80 } 81 }); 82 //跳轉上一頁 83 $(this.settings.container).on("click",".page_pre",function(){ 84 85 lists=$(_this.settings.container).find(".page_num").text(); 86 totals=$(_this.settings.container).find(".page_size").text(); 87 88 if($.isFunction(_this.settings.callBack)){ 89 if(curPage>1){ 90 curPage=curPage-1; 91 isTrue=_this.settings.callBack(curPage); 92 if(isTrue){ 93 _this.refreshDom(); 94 $(_this.settings.container).find(".page_current").text(curPage); 95 $(_this.settings.container).find(".page_jump_input").val(curPage); 96 } 97 } 98 } 99 });100 //跳轉下一頁101 $(this.settings.container).on("click",".page_next",function(){102 103 lists=$(_this.settings.container).find(".page_num").text();104 totals=$(_this.settings.container).find(".page_size").text();105 106 107 if($.isFunction(_this.settings.callBack)){108 if(curPage=1 && jumpVal <=totals){145 curPage=jumpVal;146 isTrue=_this.settings.callBack(curPage);147 if(isTrue){148 _this.refreshDom();149 $(_this.settings.container).find(".page_current").text(curPage);150 }151 }else{152 jumpVal=curPage;153 }154 }155 });156 },157 refreshDom:function(){158 $(this.settings.container).find("li.flex_child").removeClass("page_hide");159 if(Number(totals)==1){160 $(this.settings.container).find(".page_pre").addClass("page_hide");161 $(this.settings.container).find(".page_next").addClass("page_hide");162 }163 else if(Number(totals)==2){164 if(Number(curPage)==1){165 $(this.settings.container).find(".page_pre").addClass("page_hide");166 }else{167 $(this.settings.container).find(".page_next").addClass("page_hide");168 }169 }170 else if(Number(curPage)==1 && Number(totals)>2){171 $(this.settings.container).find(".page_pre").addClass("page_hide");172 }173 else if(Number(curPage)==Number(totals) && Number(totals)>2){174 $(this.settings.container).find(".page_next").addClass("page_hide");175 }176 }177 };178 179 var pageInit=function(opts){180 return new Page(opts);181 };182 183 window.pageInit= $.pageInit=pageInit;184 185 })(jQuery,window,undefined);

3.組件調用

通過 window.pageInit= $.pageInit=pageInit 可完成分頁組件初始化。

暴露出來的接口分別為:

1.container:DOM的容器,默認.page

2.setPos:DOM放置的HTML位置,默認body

3.totalPages:默認的頁數,必填,默認null

4.totalLists:默認的數據總數,必填,默認null

5.initPage:當前頁,默認第一頁

6.inputVal:跳轉頁,默認第一頁

7.callBack:執行的回調函數,必填,默認null

1 2 3

4 5 基于jQuery封裝的分頁組件 6 7 8 9 10 11 29 30

效果:

通過callBack接口,添加自己所需要執行的function函數,并且需要return true時才回執行動態的DOM渲染。

總結

以上是生活随笔為你收集整理的基于jquery的php分页,基于jQuery封装的分页组件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。