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/cart/cart.jsp

126 lines
4.1 KiB

3 years ago
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
4 weeks ago
<!-- 引入JSTL核心标签库用于简化JSP页面的内容 -->
3 years ago
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
4 weeks ago
<!-- 设置页面内容类型和字符编码 -->
3 years ago
<!DOCTYPE html>
4 weeks ago
<!-- 声明文档类型为HTML5 -->
3 years ago
<html>
<head>
4 weeks ago
<meta charset="UTF-8">
<!-- 设置页面的字符编码 -->
<title>购物车</title>
<!-- 设置页面标题 -->
3 years ago
<%@include file="/pages/common/header.jsp"%>
4 weeks ago
<!-- 引入头部文件通常包含CSS和JavaScript的引用 -->
3 years ago
<script type="text/javascript">
$(function () {
4 weeks ago
// 当文档加载完成后执行的函数
3 years ago
$("a.deleteItem").click(function () {
4 weeks ago
// 为删除按钮绑定点击事件
3 years ago
return confirm("你确定要删除【"+$(this).parent().parent().find("td:first").text() +"】么?");
4 weeks ago
// 弹出确认框询问是否删除
3 years ago
});
$("#clearCart").click(function () {
4 weeks ago
// 为清空购物车按钮绑定点击事件
3 years ago
return confirm("你确定要清空购物车么?");
4 weeks ago
// 弹出确认框询问是否清空购物车
3 years ago
});
$(".updateCount").change(function () {
4 weeks ago
// 为数量输入框绑定值改变事件
3 years ago
var name = $(this).parent().parent().find("td:first").text();
4 weeks ago
// 获取商品名称
3 years ago
var count = this.value;
4 weeks ago
// 获取输入的新数量
3 years ago
var id = $(this).attr("bookId");
4 weeks ago
// 获取商品的ID
3 years ago
if(confirm("你确定要修改【"+name+"】数量为"+count+"么?")) {
4 weeks ago
// 弹出确认框询问是否修改数量
location.href="http://localhost:8080/Book/cartServlet?action=updateCount&count="+count+"&id="+id; // 跳转到更新数量的Servlet
3 years ago
} else {
this.value = this.defaultValue;
4 weeks ago
// 如果取消,则恢复默认数量
3 years ago
}
})
});
</script>
</head>
<body>
4 weeks ago
<div id="header">
<!-- 头部区域 -->
<img class="logo_img" alt="" src="static/img/logo.jpg" >
<!-- 引入logo图片 -->
<span class="wel_word">购物车</span>
<!-- 显示欢迎文字 -->
<%@include file="/pages/common/login_success_menu.jsp"%>
<!-- 引入登录成功后的菜单 -->
</div>
<div id="main">
<!-- 主内容区域 -->
<table>
<!-- 商品列表表格 -->
<tr>
<td>商品名称</td>
<td>数量</td>
<td>单价</td>
<td>金额</td>
<td>操作</td>
</tr>
<c:if test="${empty sessionScope.cart.items}">
<!-- 判断购物车是否为空 -->
3 years ago
<tr>
4 weeks ago
<td colspan="5"><a href="index.jsp">亲,当前购物车为空,快去和小伙伴浏览书籍吧! </a> </td>
<!-- 显示购物车为空的信息 -->
3 years ago
</tr>
4 weeks ago
</c:if>
3 years ago
4 weeks ago
<c:if test="${not empty sessionScope.cart.items}">
<!-- 判断购物车是否不为空 -->
<c:forEach items="${sessionScope.cart.items}" var="entry">
<!-- 遍历购物车中的商品 -->
3 years ago
<tr>
4 weeks ago
<td>${entry.value.name}</td>
<!-- 显示商品名称 -->
<td>
<input class="updateCount" style="width: 70px;" bookId="${entry.value.id}" type="text" value="${entry.value.count}">
<!-- 数量输入框 -->
</td>
<td>${entry.value.price}</td>
<!-- 显示商品单价 -->
<td>${entry.value.totalPrice}</td>
<!-- 显示商品总价 -->
<td><a class="deleteItem" href="cartServlet?action=deleteItem&id=${entry.value.id}">删除</a></td>
<!-- 删除按钮 -->
3 years ago
</tr>
4 weeks ago
</c:forEach>
</c:if>
3 years ago
4 weeks ago
</table>
<c:if test="${not empty sessionScope.cart.items}">
<!-- 判断购物车是否不为空 -->
3 years ago
<div class="cart_info">
4 weeks ago
<!-- 购物车信息区域 -->
3 years ago
<span class="cart_span">购物车中共有<span class="b_count">${sessionScope.cart.totalCount}</span>本书籍</span>
4 weeks ago
<!-- 显示购物车中商品的总数 -->
3 years ago
<span class="cart_span">总金额<span class="b_price">${sessionScope.cart.totalPrice}</span>元</span>
4 weeks ago
<!-- 显示购物车中商品的总金额 -->
3 years ago
<span class="cart_span"><a id="clearCart" href="cartServlet?action=clearItem">清空购物车</a></span>
4 weeks ago
<!-- 清空购物车按钮 -->
3 years ago
<span class="cart_span"><a href="client/orderServlet?action=isLogin">去结账</a></span>
4 weeks ago
<!-- 去结账按钮 -->
3 years ago
</div>
4 weeks ago
</c:if>
3 years ago
4 weeks ago
</div>
3 years ago
4 weeks ago
<%@include file="/pages/common/footer.jsp"%>
<!-- 引入页脚文件 -->
3 years ago
</body>
4 weeks ago
</html>