cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
$.fn.mypagination = function(total,cpage,psize,opts){
 
    opts = $.extend({perPage:psize||1, recordCount:total||0, callback:function(){}}, opts||{});
    
    opts.totalPage = Math.ceil(total/opts.perPage);
    
    return this.each(function(){
        var currPage;
        
        if(cpage>opts.totalPage){
            currPage=opts.totalPage;
        }else{
            currPage=cpage;
        }
        
        var panel = $(this);
        
        function _gotopage(page){
            return function(){
                currPage = page;
                render();
                opts.callback(currPage);
            };
        }
        
        function turnPage(){
            var page = $(".turn-page-input",panel).val();
            if(page===""+parseInt(page)){
                page = parseInt(page);
                if(page<=opts.totalPage&&page>=1){
                    currPage = page;
                    render();
                    opts.callback(currPage);
                }else{
                    window.top.popupTips("请输入正确的页码");
                }
            }else{
                window.top.popupTips("请输入正确的页码");
            }
        }
        
    /*    function render(){
            var html = '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
              html = html + '<tbody>';
            html = html + '<tr><td align="center" class="pn-sp">共' + opts.recordCount + '条';
            html = html + '每页' + opts.perPage + '条';
            html = html + '<input class="page-first" type="button" value="首 页"/>';
            html = html + '<input class="page-prev" type="button" value="上一页"/>';
            html = html + '<input class="page-next" type="button" value="下一页"/>';
            html = html + '<input class="page-last" type="button" value="尾 页"/>';
            html = html + '<input type="text" class="turn-page-input" value="" maxlength="3" size="1"/>';
            html = html + '<button class="turn-page-btn">跳转</button>';
            html = html + '当前 ' + currPage + '/' + opts.totalPage + ' 页 ';
            html = html + '</td></tr></tbody></table>';            
            panel.empty();
            panel.append(html);
            if(currPage==1){
                $(".page-first",panel).attr("disabled",true);
                $(".page-prev",panel).attr("disabled",true);
            }else{
                $(".page-first",panel).bind('click',_gotopage(1));
                $(".page-prev",panel).bind('click',_gotopage(currPage-1));
            }
            
            if(currPage==opts.totalPage){
                $(".page-next",panel).attr("disabled",true);
                $(".page-last",panel).attr("disabled",true);
            }else{
                $(".page-next",panel).bind('click',_gotopage(currPage+1));
                $(".page-last",panel).bind('click',_gotopage(opts.totalPage));
            }
            
            $(".turn-page-btn",panel).bind('click',turnPage);
        }    
        
        */
        function render(){
        var html=$('<div class="paging clearfix"></div>');
        
        if(opts.totalPage>1){
                if(currPage>1&&currPage<=opts.totalPage){
                    html.append($("<a>上一页</a>").bind('click',_gotopage(currPage-1)));
                    //$(".page-prev",panel).bind('click',_gotopage(currPage-1));
                }else{
                    html.append("<a>上一页</a>");//上一页
                }
                
                if(currPage<6)
                
                {
                
                for(var i=1;i<=opts.totalPage&&i<=10;i++)
                {
                    if(currPage==i)
                    {
                        html.append("<a class='focus'>"+i+"</a>");
                    }else{
                        html.append($("<a>"+i+"</a>").bind('click',_gotopage(i)));
                    //html.append"<a  class=\"topage-"+i+"\" href=javascript:void(0);>"+i+"</a>";}
                    //$(".topage-"+i,panel).bind('click',_gotopage(i));
                    }
                }
                if(opts.totalPage>10)
                {
                    html.append("");
                }
                }else
                {
                    
                    for(var i=currPage-5;i<currPage&&i<=opts.totalPage;i++)
                    {
                        if(currPage==i)
                        {
                            html.append("<a class='focus'>"+i+"</a>");
                        }else{
                        html.append($("<a>"+i+"</a>").bind('click',_gotopage(i)));}
                    }
                    for(var i=currPage;i<=currPage+4&&i<=opts.totalPage;i++)
                    {
                        if(currPage==i)
                        {
                            html.append("<a class='focus'>"+i+"</a>");
                        }else{
                        html.append($("<a>"+i+"</a>").bind('click',_gotopage(i)));}
                        
                    }
                    if(opts.totalPage>currPage+5)
                    {
                        html.append("");
                    }
                    
                }
                //html.append(""+currPage+"/"+totalPage+"");
                
                
                if(currPage>=1&&currPage<opts.totalPage){
                    html.append($("<a>下一页</a>").bind('click',_gotopage(currPage+1)));
                    //$(".page-next",panel).bind('click',_gotopage(currPage+1));
                }else{
                    html.append("<a>下一页</a>");//下一页
                }
        
        html.append("<input type='text' class='turn-page-input' value='"+currPage+"'><a class='turn-page-btn'>跳转</a><a>共"+opts.totalPage+"页"+total+"条</a>");
        
        panel.empty();
        panel.append(html);
        $(".turn-page-btn",panel).bind('click',turnPage);
            
            
        }}
        render();
    });
};