JS 페이지 컨트롤 은 페이지 새로 고침 없 이 사용 할 수 있 습 니 다.

10931 단어 JS 페이지 컨트롤
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 = ""; //
    this.IsShowFristString = true; //
    this.LastBarFormat = ""; //
    this.IsShowLastString = true; //
    this.CurrentRecordBarFormat = " {0}-{1}"; //
    this.IsShowCurrentRecordString = true; //
    this.CurrentPageBarFormat = " " + this.ReplaceString + " , " + (this.PageCount == 0 ? 1 : this.PageCount) + " "; //
    this.IsShowCurrentPageString = true; //
    this.OtherBarFormat = ""; //
    this.IsShowOtherString = true; //
    var regexp = new RegExp(this.ReplaceString, "g"); //
    function GetFristPageString() {//
        if (PagerBar.FristBarFormat != "" && PagerBar.PageIndex != 1) {
            return PagerBar.FristBarFormat.replace(regexp, 1);
        }
        else {
            return "";
        }
    }
    function GetPreviouPageString() { //
        if (PagerBar.PreviouBarFormat != "") {
            if (PagerBar.RecordCount > PagerBar.PageSize && PagerBar.PageIndex != 1) {// HTML
                return PagerBar.PreviouBarFormat.replace(regexp, PagerBar.PageIndex - 1);
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetPageString() {//
        var pagestr = "";
        if (PagerBar.CurrentBarFormat != "" && PagerBar.PageBarFormat != "") {
            var ShowPageFirest = PagerBar.PageIndex - parseInt(PagerBar.ShowPagesCount / 2 + 1) < 0 ? 0 : PagerBar.PageIndex - parseInt(PagerBar.ShowPagesCount / 2 + 1); //
            if (PagerBar.PageCount < PagerBar.ShowPagesCount) {//
                ShowPageFirest = 0;
            }
            else {
                if (PagerBar.PageIndex > (PagerBar.PageCount - parseInt(PagerBar.ShowPagesCount / 2 + 1))) {//
                    ShowPageFirest = PagerBar.PageCount - PagerBar.ShowPagesCount;
                }
            }
            for (var i = ShowPageFirest; i < ShowPageFirest + PagerBar.ShowPagesCount; i++) {//
                if (PagerBar.PageIndex == i + 1) {
                    pagestr += PagerBar.CurrentBarFormat.replace(regexp, i + 1);
                }
                else {
                    pagestr += PagerBar.PageBarFormat.replace(regexp, i + 1);
                }
                if (i >= PagerBar.PageCount - 1) {//
                    break;
                }
            }
        }
        return pagestr;
    }
    function GetNextPageString() {//
        if (PagerBar.NextBarFormat != "") {
            if (PagerBar.RecordCount > PagerBar.PageSize && PagerBar.PageIndex != PagerBar.PageCount) {// HTMl
                return PagerBar.NextBarFormat.replace(regexp, PagerBar.PageIndex + 1);
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetLastPageString() {//
        if (PagerBar.LastBarFormat != "" && PagerBar.PageIndex != PagerBar.PageCount && PagerBar.RecordCount != 0) {
            return PagerBar.LastBarFormat.replace(regexp, PagerBar.PageCount);
        }
        else {
            return "";
        }
    }

    function GetFrontOtherPageString() {//
        if (PagerBar.OtherBarFormat != "") {
            if (PagerBar.PageIndex > PagerBar.ShowPagesCount / 2 + 1) {
                return PagerBar.OtherBarFormat.replace(regexp, PagerBar.PageIndex - PagerBar.ShowPagesCount <= 0 ? 1 : PagerBar.PageIndex - PagerBar.ShowPagesCount)
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetAfterOtherPageString() {//
        if (PagerBar.OtherBarFormat != "") {
            if (PagerBar.PageIndex <= PagerBar.PageCount - PagerBar.ShowPagesCount / 2) {
                return PagerBar.OtherBarFormat.replace(regexp,
                PagerBar.PageIndex + PagerBar.ShowPagesCount >= PagerBar.PageCount ? PagerBar.PageCount : PagerBar.PageIndex + PagerBar.ShowPagesCount);
            }
            else {
                return "";
            }
        }
        else {
            return "";
        }
    }
    function GetCurrentRecordPageString() {//
        if (PagerBar.CurrentRecordBarFormat != "") {
            if (PagerBar.RecordCount == 0) {
                return "";
            }
            else {
                return PagerBar.CurrentRecordBarFormat.replace("{0}", (PagerBar.PageIndex - 1) * PagerBar.PageSize + 1).replace("{1}", PagerBar.PageIndex * PagerBar.PageSize > PagerBar.RecordCount ? PagerBar.RecordCount : PagerBar.PageIndex * PagerBar.PageSize);
            }
        }
        else return "";
    }
    function GetCurrentPageBarString() {//
        if (PagerBar.CurrentPageBarFormat != "") {
            return PagerBar.CurrentPageBarFormat.replace(regexp, PagerBar.PageIndex);
        }
        else return "";
    }
    this.GetString = function (pageindex) {// HTML ( )
        if (pageindex != null && NumberRegex.test(pageindex)) {//
            this.PageIndex = parseInt(pageindex);
        }
        if (this.PageCount == 0) {// ,
            CalculatePageCount(this.PageSize, this.RecordCount);
        }
        var pagestr = "";
        if (this.IsShowCurrentPageString) {
            pagestr = GetCurrentPageBarString();
        }
        if (this.IsShowCurrentRecordString) {
            pagestr += GetCurrentRecordPageString();
        }
        if (this.IsShowFristString) {
            pagestr += GetFristPageString();
        }
        if (this.IsShowPreviouString) {
            pagestr += GetPreviouPageString();
        }
        if (this.IsShowOtherString) {
            pagestr += GetFrontOtherPageString();
        }
        if (this.IsShowPageString) {
            pagestr += GetPageString();
        }
        if (this.IsShowOtherString) {
            pagestr += GetAfterOtherPageString();
        }
        if (this.IsShowNextString) {
            pagestr += GetNextPageString();
        }
        if (this.IsShowLastString) {
            pagestr += GetLastPageString();
        }
        return pagestr;
    }
    this.GetNormalString = function (pageindex) {
        if (pageindex != null && NumberRegex.test(pageindex)) {//
            this.PageIndex = parseInt(pageindex);
        }
        if (this.PageCount == 0) {// ,
            CalculatePageCount(this.PageSize, this.RecordCount);
        }
        var pagestr = "";
        pagestr += GetFristPageString();
        pagestr += GetPreviouPageString();
        pagestr += GetPageString();
        pagestr += GetNextPageString();
        pagestr += GetLastPageString();
        return pagestr;
    }
    this.GetSimpleString = function (pageindex) {
        if (pageindex != null && NumberRegex.test(pageindex)) {//
            this.PageIndex = parseInt(pageindex);
        }
        if (this.PageCount == 0) {// ,
            CalculatePageCount(this.PageSize, this.RecordCount);
        }
        var pagestr = "";
        pagestr += GetPreviouPageString();
        pagestr += GetCurrentPageBarString();
        pagestr += GetNextPageString();
        return pagestr;
    }
}
사용 예시:
잠시 없다
내용 에 필요 한 지식 포인트 페이지 문자'\#PageLink'

좋은 웹페이지 즐겨찾기