<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%--导入JSTL标签库 --%> <%-- <jsp:include page="/NextOrderServlet"></jsp:include>导入下订单控制器 --%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>购物车</title> <link rel="stylesheet" type="text/css" href="style/Books.css"/> <script type="text/javascript"> var xhr; function ChooseToBuyAjax(){ xhr = new XMLHttpRequest();//初始化 xhr.open("POST", "ChooseToBuyAjaxServlet", true);//用异步方式发送post请求 xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//处理中文乱码问题 xhr.send("Bid="+document.getElementById("Bid").value+"&Num=" + document.getElementById("Num").value+"&Price="+document.getElementById("Price").value);//向服务器发送数据 xhr.onreadystatechange = function() {//状态改变时调用服务器响应的数据修改页面 if (xhr.readyState == 4 && xhr.status == 200) { document.getElementById("total").innerHTML = xhr.responseText;//获取服务器响应的文本 } }; }; </script> </head> <body> <div name="title"> <table align="center"> <tr> <td colspan="4"><img id="logo" src="image/logo.png"/></td> <td colspan="4"><h1>图书你的神话</h1></td> <c:choose> <c:when test="${UNAME!=null}"><%--用户名存在 --%> <td><a href="Pensonal.jsp">Hi,${UNAME}</a></td> <td><a href="">[退出]</a></td> </c:when> <c:otherwise><%--用户名不存在 --%> <td><a href="login.jsp"><input type="submit" value="登录" class="submit"/></a></td> <td><a href="NewUser.jsp"><input type="submit" value="注册" class="submit"/></a></td> </c:otherwise> </c:choose> </tr> </table> </div> <div> <h2>购物车详情</h2> <table align="center"> <tr> <th><input type="checkbox"/>全选</th> <th>图书封面</th> <th>图书名</th> <th>单价(元)</th> <th>数量</th> <th>金额(元)</th> <th>操作</th> </tr> <c:choose> <c:when test="${SHOWMINUTES!=null}"><%--显示订单详情列表存在 --%> <c:forEach var="m" items="${SHOWMINUTES}"><%--遍历显示订单详情列表 --%> <tr> <td><input type="checkbox" id="Bid" name="Bid" value="${m.getBid()}" onchange="ChooseToBuyAjax()"/></td> <td><img src="${m.getId()}" width="100px" height="100px"/></td> <td>${m.getOid()}</td> <td>¥${m.getPrice()/m.getNum()}</td> <td><input type="text" id="Num" name="Num" value="${m.getNum()}"/></td> <td><input type="text" id="Price" name="Price" value="${m.getPrice()}"/></td> <td> <dl> <dt>移入收藏</dt> <dd>删除</dd> </dl> </td> </tr> </c:forEach> </c:when> <c:otherwise><%--显示订单详情列表不存在 --%> </c:otherwise> </c:choose> <!--一页十条记录--> <tr> <td colspan="6" align="right"> <a href="#"> 总计(不含运费): <span id="total">¥0.00</sapn> </a> </td> </tr> </table> </div> <div id="end"> <hr color="#993300"/> <p align="center">版权所有©工作室</p> <p align="center">手机版下载:<a href="#">Android</a>|<a href="#">Iphone</a></p> <p align="center">联系我们:1383838438</p> </div> </body> </html>
问题出现在最后一张图片上,我要买3本书,按各自的单价计算,总计应为:106.5
但现在显示的计算结果是:买了12本高等数学的价格
这个页面的共功能是:点击每行的复选框,把每行的金额累加,也就是把所以选中复选框的金额求和,显示在总计
昵称不可以为空0
相关分类