Jquery前端分頁插件pagination使用


插件描述:JqueryPagination是一個輕量級的jquery分頁插件。只需幾個簡單的配置就可以生成分頁控件。並且支持ajax獲取數據,自定義請求參數,提供多種方法,事件和回調函數,功能全面的分頁插件。

實例圖片

jQuery Pagination分頁插件:下載:http://www.jq22.com/jquery-info5697

步驟一:導入相關的jquery和pagination文件


        <script src="js/jquery-1.11.3.js"></script>
        <!--分頁-->
        <link rel="stylesheet" href="css/pagination.css" />
        <script type="text/javascript" src="js/jquery.pagination.js"></script>

步驟二:HTML代碼:

非常簡單只需要一個div標簽

  <div class="setPageDiv">
            <div class="Pagination" id="pagination"></div>
 </div>

步驟三: JS代碼:

 $('.Pagination').pagination(pageNum, { num_edge_entries: 1, //邊緣頁數 num_display_entries: 4, //主體頁數 items_per_page: 1, //每頁顯示1項 prev_text: "上一頁", next_text: "下一頁", }); 

完整代碼實例展示:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="js/jquery-1.11.3.js"></script>
        <!--分頁-->
        <link rel="stylesheet" href="css/pagination.css" />
        <script type="text/javascript" src="js/jquery.pagination.js"></script>
        <style> .setPageDiv { width: 1100px; margin: auto; margin-bottom: 91px; margin-top: 37px; } #pagination { margin: auto; margin-left: 100px; } .img-responsive { width: 30px; height: 30px; } </style>

    </head>

    <body>
        <div class="zxdong">
            <div class="zxdong_inner">
                <ul style="margin-left: 100px;">
                    <!--<div class='row'> <div class='col-md-1 col-xs-1'> <img src='" + img + "'/ class='img-responsive'> </div> <div class='col-md-3 col-xs-3'> <p>11111111111111111 </p> </div></div>-->

                    <div class="list">

                    </div>
                </ul>

            </div>
        </div>

        <div class="setPageDiv">
            <div class="Pagination" id="pagination"></div>
        </div>

    </body>
    <script> //分頁 $(function() { $('.setPageDiv').change(function() { getMsg(parseInt($(this).val())) }) function getMsg(num) { $.ajax({ url: 'data/bussiness.json', type: 'GET', dataType: 'json', success: function(data) { //1.計算分頁數量 var showNum = num; var dataL = data.list.length; var pageNum = Math.ceil(dataL / showNum); $('.Pagination').pagination(pageNum, { num_edge_entries: 1, //邊緣頁數 num_display_entries: 4, //主體頁數 items_per_page: 1, //每頁顯示1項 prev_text: "上一頁", next_text: "下一頁", callback: function(index) { //console.log(index); var html = '<ul>' console.log(showNum * index + '~' + parseInt(showNum * index) + parseInt(showNum)) for(var i = showNum * index; i < showNum * index + showNum; i++) { //console.log(i) if(i < dataL) { var img = data.list[i].img; var manager = data.list[i].manager; //交易類型 html += "<div class='row'>"; html += "<div class='col-md-1 col-xs-1'>" html += "<img src='" + img + "'/ class='img-responsive'>" html += "</div>" html += "<div class='col-md-3 col-xs-3'>" html += "<p>" + manager + "</p>" html += "</div></div>"; } } html += '</ul>'; $('.list').html(html) } }) } }) } getMsg(6) }) </script>

</html>

數據格式:bussiness.json

{
    "list": [
        {
            "img":"img/dingwei.png",
            "manager": "新店開業刷刷送豪禮"
            
        }, {
            "img": "img/dingwei.png",
            "manager": "文史樓108"
            
        },
        {
            "img": "img/dingwei.png",
            "manager": "文史樓108"
            
        },
        {
            "img": "img/dingwei.png",
            "manager": "文史樓108"
            
        },
        
        {
            "img": "img/dingwei.png",
            "manager": "文史樓108"
            
        }
        
    ]
}


原文作者:祈澈姑娘
原文鏈接:https://www.jianshu.com/u/05f416aefbe1
創作不易,轉載請告知

90后前端妹子,愛編程,愛運營,愛折騰。
堅持總結工作中遇到的技術問題,堅持記錄工作中所所思所見,歡迎大家一起探討交流。
有個很難漲粉的的公眾號叫:【編程微刊】


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM