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
$.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);
    
    var totalPanel = this;
    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{
                    alert("请输入正确的页码");
                }
            }else{
                alert("请输入正确页码");
            }
        }
        
        
        
        function render(){
            
                var html = '<i>找到</i><span>'+opts.recordCount+'</span><i>个商品</i><em>'+currPage+'</em><i>/'+opts.totalPage+'</i>';
                html += '<a class="page-prev"><img src="'+opts.basePath+'/static/style/website/images/search6.gif" width="7" height="33" alt="" /></a>';
                html += '<a class="page-next"><img src="'+opts.basePath+'/static/style/website/images/search7.gif" width="7" height="33" alt="" /></a>';
                totalPanel.each(function() {
                    $(this).empty();
                    $(this).append(html);
                    if(currPage==1){
                        $(".page-prev",$(this)).attr("disabled",true);
                    }else{
                        $(".page-prev",$(this)).bind('click',_gotopage(currPage-1));
                    }
                    
                    if(total>psize) {
                        if(currPage==opts.totalPage){
                            $(".page-next",$(this)).attr("disabled",true);
                        }else{
                            $(".page-next",$(this)).bind('click',_gotopage(currPage+1));
                        }
                    }
                });
            
        }        
        render();
    });
};