首页 > 语言 > JavaScript > 正文

JS分页控件 可用于无刷新分页

2024-05-06 14:37:26
字体:
来源:转载
供稿:网友

JS分页控件,可用于无刷新分页

代码如下:
function PagerBar(recordcount, pagesize, pageindex, showpagecount) {
    var NumberRegex = new RegExp(/^/d+$/);
    this.PageIndex = 1; //页索引,当前页
    if (pageindex != null && NumberRegex.test(pageindex)) this.PageIndex = parseInt(pageindex);
    this.PageSize = 10; //页面大小
    if (pagesize != null && NumberRegex.test(pagesize)) this.PageSize = parseInt(pagesize);
    this.RecordCount = 0;
    if (recordcount != null && NumberRegex.test(recordcount)) this.RecordCount = parseInt(recordcount); //记录总数
    this.PageCount = 0;  //页总数
    var PagerBar = this;
    function CalculatePageCount(_pagesize, _recordcount) {//计算总页数
        if (_pagesize != null && NumberRegex.test(_pagesize)) PagerBar.PageSize = parseInt(_pagesize);
        if (_recordcount != null && NumberRegex.test(_recordcount)) PagerBar.RecordCount = parseInt(_recordcount);
        else PagerBar.RecordCount = 0;
        if (PagerBar.RecordCount % PagerBar.PageSize == 0) {//计算总也页数
            PagerBar.PageCount = parseInt(PagerBar.RecordCount / PagerBar.PageSize);
        }
        else {
            PagerBar.PageCount = parseInt(PagerBar.RecordCount / PagerBar.PageSize) + 1;
        }
    }
    if (this.RecordCount != 0) {//如果传入了记录总数则计算总页数
        CalculatePageCount(this.PageSize, this.RecordCount);
    }
    this.ReplaceString = "《#PageLink》"; //替换页数的文本,注:不可以有正则表达式中的符号
    this.ShowPagesCount = 5; //显示页数量
    if (showpagecount != null && NumberRegex.test(showpagecount.toString())) this.ShowPagesCount = parseInt(showpagecount);
    this.PreviouBarFormat = ""; //上一页显示文本格式
    this.IsShowPreviouString = true; //是否显示上一页
    this.NextBarFormat = ""; //下一页显示文本格式
    this.IsShowNextString = true; //是否显示下一页
    this.PageBarFormat = ""; //页面连接显示文本格式
    this.CurrentBarFormat = ""; //当前页显示文本格式
    this.IsShowPageString = true; //是否显示页索引
    this.FristBarFormat = ""; //首页链接显示文本格式

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选