You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookStore/web/pages/common/page_nav.jsp

90 lines
3.4 KiB

3 years ago
<%--
Created by IntelliJ IDEA.
User: jhu
Date: 2020/10/5
Time: 16:15
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="page_nav">
4 weeks ago
<!-- 首页链接 -->
3 years ago
<a href="${requestScope.page.url}&pageNo=1">首页</a>
4 weeks ago
<!-- 上一页链接 -->
<c:if test="${requestScope.page.pageNo > 1}">
<a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo - 1}">上一页</a>
3 years ago
</c:if>
4 weeks ago
<!-- 分页逻辑 -->
3 years ago
<c:choose>
<%-- 当总页码小于等于5的情况 --%>
4 weeks ago
<c:when test="${requestScope.page.pageTotal <= 5}">
3 years ago
<c:set var="begin" value="1"></c:set>
4 weeks ago
<c:set var="end" value="${requestScope.page.pageTotal}"></c:set>
3 years ago
</c:when>
<c:otherwise>
<%-- 当总页码大于5的情况 --%>
<c:choose>
<%-- 当前页码是前三 --%>
4 weeks ago
<c:when test="${requestScope.page.pageNo <= 3}">
3 years ago
<c:set var="begin" value="1"></c:set>
<c:set var="end" value="5"></c:set>
</c:when>
<%-- 当前页码是后三 --%>
4 weeks ago
<c:when test="${requestScope.page.pageNo >= requestScope.page.pageTotal - 2}">
<c:set var="begin" value="${requestScope.page.pageTotal - 4}"></c:set>
<c:set var="end" value="${requestScope.page.pageTotal}"></c:set>
3 years ago
</c:when>
<c:otherwise>
4 weeks ago
<%-- 当前页码在中间 --%>
<c:set var="begin" value="${requestScope.page.pageNo - 2}"></c:set>
<c:set var="end" value="${requestScope.page.pageNo + 2}"></c:set>
3 years ago
</c:otherwise>
</c:choose>
</c:otherwise>
</c:choose>
4 weeks ago
<!-- 显示页码 -->
<c:forEach begin="${begin}" end="${end}" var="i">
<c:if test="${i == requestScope.page.pageNo}">【${i}】</c:if>
<c:if test="${i != requestScope.page.pageNo}">
<a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
</c:if>
3 years ago
</c:forEach>
4 weeks ago
<!-- 下一页链接 -->
<c:if test="${requestScope.page.pageNo < requestScope.page.pageTotal}">
<a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo + 1}">下一页</a>
3 years ago
</c:if>
4 weeks ago
<!-- 末页链接 -->
3 years ago
<a href="${requestScope.page.url}&pageNo=${requestScope.page.pageTotal}">末页</a>
4 weeks ago
<!-- 显示总页数和总记录数 -->
3 years ago
共${requestScope.page.pageTotal}页,${requestScope.page.pageTotalCount}条记录
4 weeks ago
<!-- 跳转页码输入框 -->
3 years ago
到第<input value="${param.pageNo}" name="pn" id="pn_input"/>页
<input id="searchPageBtn" type="button" value="确定">
4 weeks ago
<!-- 跳转页码的JavaScript脚本 -->
3 years ago
<script type="text/javascript">
$(function () {
4 weeks ago
// 点击“确定”按钮时触发跳转
3 years ago
$("#searchPageBtn").click(function () {
4 weeks ago
// 获取用户输入的页码
var pageNo = $("#pn_input").val();
// 获取总页数
var pageTotal = ${requestScope.page.pageTotal};
// 校验页码范围
if (pageNo < 1) pageNo = 1;
if (pageNo > pageTotal) pageNo = pageTotal;
// 跳转到指定页码
location.href = "${requestScope.basePath}${requestScope.page.url}&pageNo=" + pageNo;
3 years ago
});
});
</script>
</div>