<%@?page?contentType="text/html;?charset=utf-8"?language="java"?import="java.sql.*"?errorPage=""?%>
<%@?taglib?uri="http://java.sun.com/jsp/jstl/core"?prefix="c"?%><%--導(dǎo)入JSTL標(biāo)簽庫?--%>
<%--?<jsp:include?page="/NextOrderServlet"></jsp:include>導(dǎo)入下訂單控制器?--%>
<%
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);//用異步方式發(fā)送post請(qǐng)求
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);//向服務(wù)器發(fā)送數(shù)據(jù)
xhr.onreadystatechange?=?function()?{//狀態(tài)改變時(shí)調(diào)用服務(wù)器響應(yīng)的數(shù)據(jù)修改頁面
if?(xhr.readyState?==?4?&&?xhr.status?==?200)?{
document.getElementById("total").innerHTML?=?xhr.responseText;//獲取服務(wù)器響應(yīng)的文本
}
};
????? };
</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="注冊(cè)"?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>單價(jià)(元)</th>
<th>數(shù)量</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="#">
???????????? 總計(jì)(不含運(yùn)費(fèi)):
???????????? <span?id="total">¥0.00</sapn>
????????????</a>
????????????</td>
????????</tr>
????</table>
</div>
<div?id="end">
<hr?color="#993300"/>
<p?align="center">版權(quán)所有©工作室</p>
<p?align="center">手機(jī)版下載:<a?href="#">Android</a>|<a?href="#">Iphone</a></p>
<p?align="center">聯(lián)系我們:1383838438</p>
</div>
</body>
</html>問題出現(xiàn)在最后一張圖片上,我要買3本書,按各自的單價(jià)計(jì)算,總計(jì)應(yīng)為:106.5但現(xiàn)在顯示的計(jì)算結(jié)果是:買了12本高等數(shù)學(xué)的價(jià)格這個(gè)頁面的共功能是:點(diǎn)擊每行的復(fù)選框,把每行的金額累加,也就是把所以選中復(fù)選框的金額求和,顯示在總計(jì)
購物車勾選購買商品,計(jì)算總計(jì),產(chǎn)生錯(cuò)誤的結(jié)果,請(qǐng)各位大神指點(diǎn)迷津!
yuantongxin
2016-05-11 14:26:04