当前位置: 首页 > 工具软件 > Pagination > 使用案例 >

pagination 插件用法

焦光霁
2023-12-01

<html>
 <head>
 <title>pagination-Demo</title>

//应用分页js

    <script src="/Js/Jquery/jquery.pagination.js" type="text/javascript"></script>
<script>

var page_index       = 1;            //当前页码数
var items_per_page      = 5;           //每页显示的条数
var num_display_entries = 5;           //前面显示的页码数
var Rcount              = 0;           //记录总数
var num_edge_entries    = 1;           //后面显示的页码数
var optInit;                           //分页对象
var html                ="";           //页面显示的内容

var data=[
{"name":'a0',pagecount:10},{"name":'a1',pagecount:10},{"name":'a2',pagecount:10},{"name":'a3',pagecount:10},
{"name":'a4',pagecount:10},{"name":'a5',pagecount:10},{"name":'a6',pagecount:10},{"name":'a7',pagecount:10},
{"name":'a8',pagecount:10},{"name":'a9',pagecount:10}];

function LoadData(page_index){

           var info = data;
            if(info.length>0)
            {  
               Rcount   = info[0].pagecount;
            }else{Rcount=0;}
            if (Rcount > 0)  //返回的行数大于0说明有数据
            {             
                $.each(info, function(i, n) {
                html +="<li>"+n.name+"</li>";  //组装页面数据  
                });
            }
            $("#data").append(html);                                                                             //将返回的数据追加到表格
            //加载分页控件内容    
            if(parseInt(page_index)==0)
            {
                optInit = getOptionsFromForm(LoadData);       // Create pagination element with options from form 
               $("#bj_Pagination_del").pagination(Rcount, optInit);
               }

}

//funName 代表加载的方法

function getOptionsFromForm(funName) {
    var opt = {callback: funName };
    opt["items_per_page"] = items_per_page;
    opt["num_display_entries"] = num_display_entries;
    opt["num_edge_entries"] = num_edge_entries;
    opt["prev_text"] = "<";
    opt["next_text"] = ">";
   
    var htmlspecialchars = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }
    $.each(htmlspecialchars, function(k, v) {
        opt.prev_text = opt.prev_text.replace(k, v);
        opt.next_text = opt.next_text.replace(k, v);
    })
    return opt;
}
LoadData(0);//加载数据

</script>

</head>

<body>

<div ><ul id="data"></ul></div>

    <div id="bj_Pagination_del" ></div>

</body>

</html>

 

 类似资料: