• jsp分页


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ include file="/decorators/includes/taglibs.jsp"%>
    <!-- 
        ectable样式的分页
     -->
    <script type="text/javascript">
    <!--
        function toPage(pageNum){
            $("#pageNum").val(pageNum);
            $("#qform").submit();
        }
        function goPage(){
            if(isNaN($("#_page_No_").val())){
                alert("页码不正确");
                return;
            }
            toPage($("#_page_No_").val()-1);
        }
    //-->
    </script>
    <table border="0" cellspacing="0" cellpadding="0" class="tableRegion" width="100%">
    <tbody>
        <tr style="padding: 0px;">
            <td style="border: 0px solid #CCC;">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tbody>
                        <tr>
                            <td class="statusBar" align="center"><span style="color: red">${totalCount }</span> 条记录, 
                                当前显示 <span style="color: red">${totalCount==0?0:pageSize*(pageNum-1)+1 }</span><span style="color: red">
                                    <c:choose>
                                        <c:when test="${pageSize*pageNum > totalCount }">${totalCount }</c:when>
                                        <c:otherwise>${pageSize*pageNum }</c:otherwise>
                                    </c:choose>
                                </span>&nbsp;&nbsp;&nbsp;&nbsp;
                                <c:if test="${totalPage > 1 }">
                                    <c:choose>
                                        <c:when test="${pageNum > 1 }">
                                            <span onclick="toPage(${pageNum - 2 })" style="margin: 4px;cursor:pointer;" title="上一页">上一页</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span style="margin: 4px;">上一页</span>
                                        </c:otherwise>
                                    </c:choose>
                                    
                                    <!-- 显示中间的页数 -->
                                    <c:choose>
                                        <c:when test="${totalPage <= 10}">
                                            <c:forEach var="indexNo" begin="1" end="${totalPage}">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </c:when>
                                        <c:when test="${pageNum < 10 && totalPage > 10}">
                                            <c:forEach var="indexNo" begin="1" end="10">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                            <span style="margin: 4px;color:red">...</span>
                                            <span onclick="toPage(${totalPage-1})" style="margin: 4px;cursor:pointer;">${totalPage}</span>
                                        </c:when>
                                        <c:when test="${pageNum >= 10 && pageNum < totalPage-1}">
                                            <span onclick="toPage(0)" style="margin: 4px;cursor:pointer;">1</span>
                                            <span style="margin: 4px;color:red">...</span>
                                            <c:forEach var="indexNo" begin="${pageNum-7 }" end="${pageNum+2 }">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                            <c:if test="${(pageNum+2) < totalPage }">
                                                <span style="margin: 4px;color:red">...</span>
                                                <span onclick="toPage(${totalPage-1})" style="margin: 4px;cursor:pointer;">${totalPage}</span>
                                            </c:if>
                                        </c:when>
                                        <c:otherwise>
                                            <span onclick="toPage(0)" style="margin: 4px;cursor:pointer;">1</span>
                                            <span style="margin: 4px;color:red">...</span>
                                            <c:forEach var="indexNo" begin="${totalPage-9 }" end="${totalPage }">
                                                <c:choose>
                                                    <c:when test="${pageNum == indexNo}">
                                                        <span style="margin: 4px;color:red">${indexNo }</span>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span onclick="toPage(${indexNo-1 })" style="margin: 4px;cursor:pointer;">${indexNo }</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </c:otherwise>
                                    </c:choose>
                                    <!-- 显示中间的页数 结束 -->
                                    
                                    <c:choose>
                                        <c:when test="${totalPage > 1 && pageNum < totalPage}">
                                            <span onclick="toPage(${pageNum })" style="margin: 4px;cursor:pointer;" title="下一页">下一页</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span style="margin: 4px;">下一页</span>
                                        </c:otherwise>
                                    </c:choose>
                                    <input type="text" style=" 20px; height: 16px; margin-right: 4px;" id="_page_No_" value="${pageNum }">
                                    <button onclick="goPage()" style="height: 20px;">GO</button>
                                </c:if>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>        
    </tbody>
    </table>

    效果如下:

  • 相关阅读:
    AngularJs学习笔记(一)----------关于数据绑定
    水平垂直居中常见方式总结
    左边固定,右边自适应常见方式总结
    关于JavaScript的设计模式--笔记(1)
    SQL 分组后获取其中一个字段最大值的整条记录
    .NET交流 259868462
    C#可以自动在后台为属性创建字段
    委托的一个实例
    encodeURIComponent()对js参数进行编码,防止错误值
    相同的sql 分页查询结果
  • 原文地址:https://www.cnblogs.com/yushouling/p/5036417.html
Copyright © 2020-2023  润新知