js的几种分页

2020-11-27 02:55

阅读:532

标签:style   class   java   tar   ext   color   

1.
function lastStart(pageIndex,size){
                    for(i=pageIndex-1;i>=0;i--){
                        if(i%size==0){
                            return i+1;
                        }
                    }
                }
                function firstEnd(pageIndex,totalPage,size){
                    for(i=pageIndex;i
                        if(i%size==0){
                            return i;
                        }
                    }
                    return totalPage;
                }
                function drawPage(total, pageIndex, pageSize) {
                    if (!total || total == "" || total == 0) {
                        total = 1;
                    }
                    var totalPage = parseInt(((total - 1) / pageSize) + 1);
                
                    var pageHtml = [‘首页‘];
                    if (pageIndex == 1) {
                        pageHtml.push(‘);
                    } else {
                        pageHtml.push();
                        pageHtml.push(pageIndex - 1);
                        pageHtml.push(‘)">);
                    }
                    if (totalPage 
                        for (var i = 1; i 
                            if (pageIndex == i) {
                                pageHtml
                                        .push();
                                pageHtml.push(i);
                                pageHtml.push(‘)">‘);
                                pageHtml.push(i);
                                pageHtml.push(‘‘)
                            } else {
                                pageHtml.push();
                                pageHtml.push(i);
                                pageHtml.push(‘)">‘);
                                pageHtml.push(i);
                                pageHtml.push(‘‘)
                            }
                        }
                    } else {
                        var start = lastStart(pageIndex,5);
                        var end = firstEnd(pageIndex,totalPage,5);
                        if(start>1){
                            pageHtml.push(+(start-1)+‘)">…‘);
                        }
                        for (var i = start; i 
                            if (pageIndex == i) {
                                pageHtml
                                        .push();
                                pageHtml.push(i);
                                pageHtml.push(‘)">‘);
                                pageHtml.push(i);
                                pageHtml.push(‘‘);
                            } else {
                                pageHtml.push();
                                pageHtml.push(i);
                                pageHtml.push(‘)">‘);
                                pageHtml.push(i);
                                pageHtml.push(‘‘);
                            }
                        }
                        if(end
                            pageHtml.push(+(end+1)+‘)">…‘);
                        }
                    }
                    if (pageIndex 
                        pageHtml
                                .push();
                        pageHtml.push(Number(pageIndex) + 1);
                        pageHtml.push(‘)">>‘);
                    } else {
                        pageHtml
                                .push(‘>‘);
                    }
                    pageHtml.push();
                    pageHtml.push(totalPage);
                    pageHtml.push(‘)">尾页‘);
                
                    pageHtml
                            .push(
确定‘
);
                    $("div.chan_table_page").html(pageHtml.join(‘‘));
                    $("#goPage").click(function() {
                        var toPageIndex = $("#toPage").val();
                        if (!toPageIndex || !/^\d+$/.test(toPageIndex)
                                || toPageIndex > totalPage) {
                            showAlert("您输入的页码不在范围内");
                        } else {
                            funSearch(toPageIndex);
                        }
                    });
                }

2.
function drawPage(total, pageIndex, pageSize) {
    if (!total || total == "" || total == 0) {
        total = 1;
    }
    var totalPage = parseInt(((total - 1) / pageSize) + 1);
    var length = totalPage - pageIndex;
    // var temp = pageIndex;
    var pageHtml = [‘首页‘];
    if (pageIndex == 1) {
        pageHtml
                .push(‘);
    } else {
        pageHtml
                .push();
        pageHtml.push(pageIndex - 1);
        pageHtml.push(‘)">);
    }
    if (totalPage 
        for (var i = 1; i 
            if (pageIndex == i) {
                pageHtml
                        .push();
                pageHtml.push(i);
                pageHtml.push(‘)">‘);
                pageHtml.push(i);
                pageHtml.push(‘‘)
            } else {
                pageHtml.push();
                pageHtml.push(i);
                pageHtml.push(‘)">‘);
                pageHtml.push(i);
                pageHtml.push(‘‘)
            }
        }
    } else {
        var temp = pageIndex > 2 ? pageIndex - 2 : 1;
        var plen = null;
        if (pageIndex 
            plen = 3;
        } else if (pageIndex == totalPage) {
            plen = pageIndex;
        } else {
            plen = pageIndex + 1;
        }
        for (var i = temp; i 
            if (pageIndex == i) {
                pageHtml
                        .push();
                pageHtml.push(i);
                pageHtml.push(‘)">‘);
                pageHtml.push(i);
                pageHtml.push(‘‘);
            } else {
                pageHtml.push();
                pageHtml.push(i);
                pageHtml.push(‘)">‘);
                pageHtml.push(i);
                pageHtml.push(‘‘);
            }
        }
        if (pageIndex + 1 
            pageHtml.push("……");
        }
        var star = totalPage - 1;
        if (star 
            star = pageIndex + 2;
        }
        for (var i = star; i 
            pageHtml.push();
            pageHtml.push(i);
            pageHtml.push(‘)">‘);
            pageHtml.push(i);
            pageHtml.push(‘‘);
        }
    }
    if (pageIndex 
        pageHtml
                .push();
        pageHtml.push(Number(pageIndex) + 1);
        pageHtml.push(‘)">>‘);
    } else {
        pageHtml
                .push(‘>‘);
    }
    pageHtml.push();
    pageHtml.push(totalPage);
    pageHtml.push(‘)">尾页‘);
    pageHtml
            .push(
确定‘
);
    $("div.chan_table_page").html(pageHtml.join(‘‘));
    $("#goPage").click(function() {
        var toPageIndex = $("#toPage").val();
        if (!toPageIndex || !/^\d+$/.test(toPageIndex)
                || toPageIndex > totalPage) {
            alert("您输入的页码不在范围内");
        } else {
            funSearch(toPageIndex);
        }
    });
}
3.
function drawPage(total, pageIndex, pageSize) {
if (!total || total == "" || total == 0) {
total = 1;
}
var totalPage = parseInt(((total - 1) / pageSize) + 1);
var pageHtml = [‘首页‘];
if (pageIndex == 1) {
pageHtml.push(‘<‘);
} else {
pageHtml.push(‘<‘);
}

var startnum=pageIndex-3;
var endnum=pageIndex+2;
if(startnum
startnum=1;
endnum=6;
}
if(endnum>totalPage){
endnum=totalPage;
startnum=totalPage-5;
}
if(totalPage
startnum=1;
endnum=totalPage;
}
if(pageIndex>4&&totalPage>6){
pageHtml.push("");
}
for (var i =startnum; i
if (pageIndex == i) {
pageHtml
.push(‘‘);
pageHtml.push(i);
pageHtml.push(‘‘)
} else {
pageHtml.push(‘‘);
pageHtml.push(i);
pageHtml.push(‘‘)
}
}
 
if(pageIndex6){
pageHtml.push("");
}
 

if (pageIndex
pageHtml
.push(‘>‘);
} else {
pageHtml
.push(‘>‘);
}
pageHtml.push(‘尾页‘);
pageHtml
.push(‘
确定‘);
$("div.chan_table_page").html(pageHtml.join(‘‘));

$("#goPage").click(function() {
var toPageIndex = $("#toPage").val();
if (!toPageIndex || !/^\d+$/.test(toPageIndex)
|| toPageIndex > totalPage) {
showAlert("您输入的页码不在范围内");
} else {
funSearch(toPageIndex);
}
});
}

来自为知笔记(Wiz)

js的几种分页,搜素材,soscw.com

js的几种分页

标签:style   class   java   tar   ext   color   

原文地址:http://www.cnblogs.com/headwolf/p/333eb29d3a5f50683ca59e5a709d26bb.html


评论


亲,登录后才可以留言!