PHP中文俱乐部's Archiver

thankwsx 发表于 2006-11-15 16:58

ThankWsx代码-分页代码[JS][GPL]

注意,是JavaScript的哦,
还有单独使用没有效果,
我这个是结合Ajax来实现的,
以后后完善这个帖子的,
单独使用只能看看样子。
[php]
SmartKeyword = new Object();
SmartKeyword.PageSplit = function (t,start,n) {
        this.total_record = t;
        this.start_record = start;
        this.perpage_record = n;
        this.end_record = (this.start_record + this.perpage_record ) >this.total_record ? this.total_record : this.start_record + this.perpage_record;
        this.total_page = Math.ceil(this.total_record / this.perpage_record );
        this.current_page = Math.ceil(this.start_record / this.perpage_record);
        this.page =new Array(1,10,20,30,50,100,200,500);
}
SmartKeyword.PageSplit.prototype.show = function() {
        var code = "<table class='fenye' width='94%'>";
        code += "<form><tr><td>&nbsp&nbsp;^记录总数^:<span id='total_record'>"+this.total_record+"</span>";
        code += "&nbsp;&nbsp;^每页显示^:";
        code += this.select_generate(" id='perpage_record' ");
        code += "<input type='button' value='GO' class='navBtn' onclick='change_num(this);' /></td><td align='right'>";
        code += this.pageimage(1);
        code += this.pagetext();
        code += this.pageimage(2);
        code += "&nbsp;&nbsp;^当前页^:<span id='current_page'>"+this.current_page+"</span>";
        code += "&nbsp;&nbsp;^总页数^:"+this.total_page+"</td></tr></form></table>";
        return code;
}
SmartKeyword.PageSplit.prototype.pageimage = function(option) {
        var code ="";
        var imgHtml = new Array();
        var img = new Array("first","prev","next","last");
        for(i=0;i<img.length;i++) {
                imgHtml.push("<img src='../images/"+img[i]+".gif' border=0 />");
        }
        if(this.total_page > 1 ) {
                if(this.current_page > 1 && this.current_page == this.total_page) {
                        if(option == 1)
                                code = "<a onclick='change_cpage(1);'>"+imgHtml[0]+"</a>&nbsp;&nbsp;<a onclick='change_cpage("+(this.current_page-1)+")'>"+imgHtml[1]+"</a>";
                        else
                                code = imgHtml[2]+"&nbsp;&nbsp;"+imgHtml[3];
                } else if(this.current_page > 1 && this.current_page != this.total_page) {
                        if(option == 1)
                                code = "<a onclick='change_cpage(1);'>"+imgHtml[0]+"</a>&nbsp;&nbsp;<a onclick='change_cpage("+(this.current_page-1)+")'>"+imgHtml[1]+"</a>";
                        else
                                code = "<a onclick='change_cpage("+(this.current_page+1)+")'>"+imgHtml[2]+"</a>&nbsp;&nbsp;<a onclick='change_cpage("+this.total_page+")'>"+imgHtml[3]+"</a>";
                } else {
                        if(option == 1)
                                code = imgHtml[0]+"&nbsp;&nbsp;"+imgHtml[1];
                        else
                                code = "<a onclick='change_cpage("+(this.current_page+1)+")'>"+imgHtml[2]+"</a>&nbsp;&nbsp;<a onclick='change_cpage("+this.total_page+")'>"+imgHtml[3]+"</a>";
                }
        } else {
                if(option == 1)  
                        code = imgHtml[0]+"&nbsp;&nbsp;"+imgHtml[1];
                else
                        code = imgHtml[2]+"&nbsp;&nbsp;"+imgHtml[3];
        }
        return code+"&nbsp;";
}
SmartKeyword.PageSplit.prototype.pagetext = function() {
        var code="";
        var textnum = 10;
        var textstart = this.current_page-5;
        textstart = (textstart < 1) ? 1: textstart;
        var textend = this.current_page + (textnum - (this.current_page - textstart ));
        textend = (textend < 1) ? 1 : textend;
        textend = (textend <= this.total_page)?textend:this.total_page;
        for(i=textstart;i<=textend;i++) {
                if (i==this.current_page) {
                        code +="<span>"+this.current_page+"</span>&nbsp;";
                } else {
                        code +="<a onclick='change_cpage("+i+");'>"+i+"</a>&nbsp;";
                }
        }
        return code;
}
SmartKeyword.PageSplit.prototype.select_generate = function (property) {
        var code = "<select "+property+">";
        for(i=0;i<this.page.length;i++) {
                if(this.page[i] == this.perpage_record)
                        code += "<option value='"+this.page[i]+"' selected>"+this.page[i]+"</option>";
                else
                        code += "<option value='"+this.page[i]+"'>"+this.page[i]+"</option>";
        }
        code +="</select>";
        return code;
}
[/php]
使用方法如下,
[php]
<script>
var mp2 = new SmartKeyword.PageSplit(5050,411,10);
document.write(mp2.show());
</script>
[/php]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.