分页

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function (window) {
    function myPaginationArray(totalPage, currentPage) {
        var myPage = [];
        if (totalPage < 10) {
            for (var i = 0; i < totalPage; i++) {
                var page = { pagination: i + 1, currentPage: currentPage };
                myPage.push(page);
            }
        } else {
            if (currentPage > 5) {
                if (currentPage + 5 >= totalPage) {
                    for (var i = currentPage - 5 + 1; i <= totalPage; i++) {
                        var page = { pagination: i, currentPage: currentPage };
                        myPage.push(page);
                    }
                } else {
                    for (var i = currentPage - 5 + 1; i <= currentPage + 5; i++) {
                        var page = { pagination: i, currentPage: currentPage };
                        myPage.push(page);
                    }
                }
 
            } else {
                for (var i = 0; i < 10; i++) {
                    var page = { pagination: i + 1, currentPage: currentPage };
                    myPage.push(page);
                }
            }
        }
        return myPage;
    }
 
    var listPager = {
        fullPagination: function (option) {
            option = $.extend({
                totalPage: 0,
                page: 0,
                pageContent: ''
            }, option);
 
            var pageFooter = {
                total: option.totalPage,
                prev: option.page - 1,
                next: option.page + 1,
                page: option.page
            };
            if (option.page == option.total) {
                pageFooter.next = option.total;
            }
            if (option.page == 1) {
                pageFooter.prev = 1;
            }
 
            pageFooter.list = myPaginationArray(option.totalPage, option.page);
 
            if (option.pageContent) {
                $("#list_page_footer").tmpl(pageFooter).appendTo(option.pageContent);
            }
        }
    }
 
    window.listPager = listPager;
 
})(window)

  

posted @   黎明之光123  阅读(122)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示