您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“bootstrap-paginator服務(wù)器端分頁(yè)使用的示例分析”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“bootstrap-paginator服務(wù)器端分頁(yè)使用的示例分析”這篇文章吧。
HTML:
<script src="../js/jquery-3.2.1.min.js"></script> <script src="../js/bootstrap.min.js"></script> <script src="../js/bootstrap-paginator.min.js"></script> <!-- 主內(nèi)容列表 --> <ol class="list-group" id="infoList> <li class="list-group-item"><span class="fa fa-cog fa-spin fa-fw"></span>正在讀取數(shù)據(jù)……</li> </ol> <!-- 分頁(yè)導(dǎo)航器 --> <div > <ul id="useroption" class="pagination"></ul> </div>
JS:
//讀取消息列表*************************************************// queryInfoList(paraValue); function queryInfoList(bid) { $.ajax({ async: true, type: "get", url: "../php/list.php",//向后端發(fā)送請(qǐng)求,后端為PHP dataType: "json", //要求后端返回?cái)?shù)據(jù)為JSON格式 data: { page: '1',bid:bid,act:'getInfoList' }, //請(qǐng)求參數(shù),首次請(qǐng)求頁(yè)碼為1 cache: false, success: function (data) { lis = ""; for (eachRs in data.rs) {//拼接對(duì)應(yīng)<li>需要的值 lis += "<li class='list-group-item'><a title='"+data.rs[eachRs]['title']+"' class='newsLink' href='read.html?id="+data.rs[eachRs]['id']+"'>" + data.rs[eachRs]['title'] + "</a> <span class='text-muted pull-right'>"+data.rs[eachRs]['posttime']+"</span></li>"; }; $("#infoList").html(lis); var currentPage = data.CurrentPage; //當(dāng)前頁(yè)數(shù) var pageCount = data.pageCount; //總頁(yè)數(shù) var options = { bootstrapMajorVersion: 4, //版本 currentPage: currentPage, //當(dāng)前頁(yè)數(shù) totalPages: pageCount, //總頁(yè)數(shù) numberOfPages: 10,//分頁(yè)器顯示10條 shouldShowPage: true,//是否顯示該按鈕 itemTexts: function (type, page, current) { switch (type) { case "first": return "首頁(yè)"; case "prev": return "上頁(yè)"; case "next": return "下頁(yè)"; case "last": return "末頁(yè)"; case "page": return page; } }, //點(diǎn)擊事件,用于通過Ajax來刷新整個(gè)list列表 onPageClicked: function (event, originalEvent, type, page) { $.ajax({ async: true, url: "../php/list.php", type: "get", dataType: "json", data: { page: page,bid:bid ,act:'getInfoList'}, cache: false, success: function (data) { lis = ""; for (eachRs in data.rs) {//拼接對(duì)應(yīng)<li>需要的值 lis += "<li class='list-group-item'><a title='"+data.rs[eachRs]['title']+"' class='newsLink' href='read.html?id="+data.rs[eachRs]['id']+"'>" + data.rs[eachRs]['title'] + "</a> <span class='text-muted pull-right'>"+data.rs[eachRs]['posttime']+"</span></li>"; }; $("#infoList").html(lis); }/*success*/ }); } }; $('#useroption').bootstrapPaginator(options); }/*success*/ }); }
PHP:
if($act=='getInfoList') { $bid=addslashes($_REQUEST['bid']); $curPage=addslashes($_REQUEST['page']);//當(dāng)前頁(yè)碼 $pageSize=15; //每頁(yè)條數(shù) $rsAll=$dbh->query("select count(id) from article where board=$bid and wid=30 and auditor is not null and accessable=1")->fetchAll(); $rsAllCount=$rsAll[0][0];//總記錄數(shù) //計(jì)算總頁(yè)數(shù) if($rsAllCount%$pageSize==0) $pageAllCount=$rsAllCount/$pageSize; else $pageAllCount=intval($rsAllCount/$pageSize)+1; $beginRs=($curPage-1)*$pageSize; //計(jì)算起始記錄 $curRsSql="select id,title, posttime from article where board=$bid and wid=30 and auditor is not null and accessable=1 order by posttime desc limit $beginRs,$pageSize"; $rsCur=$dbh->query($curRsSql)->fetchAll(); echo(json_encode(array("rs"=>$rsCur,"pageCount"=>$pageAllCount,"curPage"=>$curPage,"sql"=>$curRsSql))); }
以上是“bootstrap-paginator服務(wù)器端分頁(yè)使用的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。