㈠ 购物车的Java代码
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;public class ShoppingCartManager {
HashMap<String, String> hm=new HashMap<String, String>();
float totlePrice=0;
//添加book到购物车
public void addBook(String bookId,String bookQuantity){
if(hm.containsKey(bookId)){
int value=Integer.parseInt(hm.get(bookId));
value+=Integer.parseInt(bookQuantity);
hm.put(bookId, value+"");
}else{
hm.put(bookId, bookQuantity);
}
}
//修改数量
public void updateQuantity(String bookId,String bookQuantity){
hm.put(bookId, bookQuantity);
}
//获取购物车的所有信息 并计算总价
public ArrayList<BookBean> getShoppingCart(){
ArrayList<BookBean> al=new ArrayList<BookBean>();
Iterator<String> i=hm.keySet().iterator();
String ids="";
BookTableManager btm=new BookTableManager();
while(i.hasNext()){
ids=ids+","+i.next();
}
al= btm.selectByBookIds(ids);
totlePrice=0; //清空总价,防止无限累计
for(int j=0;j<al.size();j++){
BookBean bb=al.get(j);
totlePrice+=bb.getPrice()*Integer.parseInt(getQuantityById(bb.getBookId()+""));
}
return al;
}
//获取总价
public float getTotlePrice(){
return totlePrice;
}
//根据ID获取数量
public String getQuantityById(String id){
String quantity=hm.get(id);
return quantity;
}
//清空购物车
public void clear(){
hm.clear();
}
//删除购物车中的一本书
public void deleteById(String id){
hm.remove(id);
}
}
㈡ asp网站 统计购物车里商品总数 代码(已有basket 表)
<%
Set QuantityRs = Server.CreateObject("ADODB.RecordSet")
SQL = "Select Sum(Count) as ProctCount From [basket]" '将Count数量字段的值相加并回存答入ProdctCount变量
QuantityRs.Open SQL,Conn,1,1
Response.Write ProctCount
%>
㈢ java购物车数量修改
你是抄form表单提交的吗?form是怎么写的袭,input的name做区分了吗,没有的话默认第一个。这种情况建议用ajax。
好吧我看了一眼你的Controller
publicObjectedit(@RequestParam(value="id")intid,@RequestParam(value="number")intnumber,HttpSessionsession,Modelmodel)
...
carService.save(car);
先不说别的,你获取和保存都是一个,第二个怎么可能会变。。。
㈣ 求php增加购物车数量的加减,
伪代码:
前端:在你页面上数量那栏增加
<div class="quantity-form"><a href="javascript:void(0);" clstag="cart_num_down" class="decrement disabled" id="decrement_8888_526830_1_1">-</a>
<input autocomplete="off" type="text" class="itxt" value="1" id="changeQuantity_8888_526830_1_1_0" minnum="1">
<a href="javascript:void(0);" clstag="cart_num_up" class="increment" id="increment_8888_526830_1_1_0">+</a>
</div>
你的购物车是个循环列表,可以去得到,每个商品的信息:id是商品
function cart_num_up(id,uid){
$.ajax({
type: "POST",
url: "CART_num.PHP",
data: {id:id, num:-1,uid:uid},
dataType: "json",
success: function(data){
if(data.status==1){
});
});
}
function cart_num_down(id,uid){
$.ajax({
type: "POST",
url: "CART_num.PHP",
data: {id:id, num:1,uid:uid},
dataType: "json",
success: function(data){
if(data.status==1){
});
});
}
点一次 加或减按钮,触发js向后端发起ajax请求:返回的是增加成功和失败状态和剩余数量;
CART_num.PHP
$id = (int)$_POST['id'];
$num = (int)$_POST['num'];
$uid =(int)$_POST['uid']; //有封装获取post或get函数更好
//查库看库存
$sort = get_kucun_num();
//查看购物车目前数量
$cart_num = get_cart_num(uid,id);
//判断库存
if($sort >$cart_num){
}else{
}
if($num<0){
//减法 $sql =“update cart set cart_num = cart_num-1 where uid =uid and id =id ”
if(($cart_num-1)>1){
}else{
}){
//加法 $sql =“update cart set cart_num = cart_num+1 where uid =uid and id =id ”
}else{
//不正确的请求
}
㈤ 该如何写购物车数量效果代码
代码我先不贴了,我提供下思路,具体的写法你自己会的。分数你看回着给啦
首先得到该产品答的数量最大值
获取文本框的onchange事件,在此事件中,比较文本值和最大值,如果小于最大值,就不做任何操作,如果大于最大值,就弹出对话框,已经超过了最大数量,或者在页面上设置一个显示提示信息的文本框。
㈥ 请问,你知道帝国cm会员空间模板调用购物车购物数量的代码吗
根据购物车COOKIE的格式,我们得到栏目ID,内容ID,购买数量(不一定是必须的),之后组合格式,删除COOKIE中的此段内容,重新打开购物车/或刷新购物车页面,这样就可以不用调整购物车,二直接删除某件商品;
要点:
1.需要一个PHP脚本页从用户删除商城COOKIE中删除提交的商品
2.为了直观方便体验好,还是使用AJAX效果(trylife使用的是JQuery),所以又下面2条
3.给购物车商品行加个ID格式为:proct-栏目ID-信息ID-购买数量
3.商品行每行增加一个删除按钮
3.一个ajax函数用于处理删除动作
文件修改与增加:
修改文件:e/template/ShopSys/buycar.php 商城购物车模板
增加问津:e/trylife/ShopSys-demo/del-proct.php 删除单个商品处理文件
购物车cookie声明与读取
声明: SetBuycar($buycar) e/class/ShopSysFun.php
读取: $buycar=getcvar(‘mybuycar’);
帝国CMScookie操作函数查看《esetcookie() getcvar() -帝国CMS cookie 操作函数》
这样做下来就是做这个购物车的代码。
㈦ ASP如何更改购物车中商品数量和计算总价
这是因为当购物车有两种或以上的商品时,你的actionid的值就会变成形如"12, 22, 25"的形式,成了字符串,而不是数值型,所以会出错,
我帮你修改了一下,就是把那个form表单位置改改就行了,改成每个商品都在自己的一个form表单里,这样就不会出错了!!
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open mallDSN
set rs=server.createobject("ADODB.Recordset")
rs.open "select actionid,id,cpsl,yunfei,proctnum,goods,style,state,paid from orders1 where username='"&username&"' and yunfei=0 ",conn,1,3
do while not rs.eof%>
<form name="form" method="post" action="add.asp?action=cpsl&actionid=<%=rs("actionid")%>">
<tr bgcolor="#FFFFFF">
<td width="7%" height="89" align="center" style='PADDING-LEFT: 5px'><input name="id" type="checkbox" checked="checked" value="<% = rs("id") %>" />
</td>
<td align="left" style='PADDING-LEFT: 5px' width="16%"><div align="center"><img src="<% = rs("goods")%>" width="75" height="75" border="0" /></div></td>
<td align="center" width="13%"><a class="a5" href="proct.asp?id=<% = rs("id") %>" target="_blank">
<% = rs("proctnum") %>
</a></td>
<td align="center" width="13%"><font color="#FF0000"> <%=rs("paid")%></font> 元</td>
<td align="center" width="13%"><font color="#FF0000">
<input name="cpsl" type="text" id="cpsl" style="font-size:12px" value="<% = rs("cpsl")%>" size=3 maxlength=20>
</font></td>
<td align="center" width="13%">
<input type="submit" name="Submit4" value="修改"></td>
<td align="center">
<%
response.Write "<a href=add.asp?action=del&actionid="&rs("actionid")&">"
response.Write "<img src=images/trash.gif border=0></a></td></tr></form>"
rs.movenext
loop
rs.close
set rs=nothing
response.write "<tr><td height=36 colspan=6 bgcolor=#FFFFFF ><div align=center> "
if action<>"addtocart" then
%>
<input name="Submit22" type="button" onclick="MM_goToURL('parent','proct.asp');return document.MM_returnValue" value="继续购物" />
<input name="Submit23" type="button" value="去收银台" onclick="this.form.action='zxoderok.asp';this.form.submit()" />
<%
end if
%>
</td>
</tr>
</table>
试试看,还有问题就给我在网络里留言!
㈧ 无刷新修改购物车产品数量得总金额的js代码
用你给的代码基础上用了一个最简单的js计算,数量是键盘输入,也可以在左右两侧加上自增减的操作,望采纳!
<table width="500" border="0" cellpadding="5" cellspacing="0">
<tr><td>数量</td><td>单价</td></tr>
<tr>
<td><input type="text" id="num" value="1" size="5" onchange="setTotal();"/></td>
<td><span id="fare">6.00</span>元</td>
</tr>
<tr>
<td> </td>
<td>总金额:¥:<span id="total_Price">6</span>.00</td>
</tr>
</table>
<p>数量那里最好能键盘输入,不然买100件就有的点了。麻烦再给看看哈</p>
<script type="text/JavaScript">
function setTotal(){
var fare=document.getElementById("fare").innerHTML;
//alert(fare);
var num=document.getElementById("num").value;
if(/\D/.test(num)){//检查用户输入的值是否是数字
alert("请您输入正确的数量!");
document.getElementById("total_Price").innerHTML="0"
}else{
document.getElementById("total_Price").innerHTML=parseFloat(fare*num);
}
}
</script>
㈨ 如何用jquery写多个购物车的数量曾减,我用jquery写了但只第一个购物车增减有用,其它的无效,代码如下:
这个时候就像前面大哥说的 不能用来表示了 可以用class
还有你的这个结构是不规范的 id一个页面只能是唯一的
为了不同时改变 其他的购物车的数量 可以来找到相对的
这个结构:
<div>
<p>单价:3.95</p>
<input class="min" name="" type="button" value="-" />
<input class="text_box" name="" type="text" value="4" />
<inputclass="add" name="" type="button" value="+" />
<p>总价:<label class="total"></label></p>
</div>
<div>
<p>单价:3.95</p>
<input class="min" name="" type="button" value="-" />
<input class="text_box" name="" type="text" value="4" />
<input class="add" name="" type="button" value="+" />
<p>总价:<label class="total"></label></p>
</div>
把每个购物车用一个div包起来
js:
$(function(){
//var t = $("#text_box");
$(".add").click(function(){
var t= $(this).parent().find(".text_box"); //根据这个来找到它相对的元素 当然也可以直接 //$(this).prev(); 这个直接来找到
t.val(parseint(t.val()+1);
setTotal($(this),t.val());
})
$(".min").click(function(){
var t= $(this).parent().find(".text_box"); //根据这个来找到它相对的元素 当然也可以直接 //$(this).next(); 这个直接来找到
t.val(parseint(t.val()-1);
setTotal($(this),t.val());
})
function setTotal(obj,number){
var total=number*$(obj).parent().find("p:first").text(); //这里算出总价
$(obj)).parent().find("total").html(total.toFixed(2));
}
// setTotal();
})
给一个建议 以后要想做好东西 布局一定要好
一个好的结构 才能让你任意操作
㈩ 急,写一个购物车的代码
我好像有一个类似的,购物车,回去给你找找,报个QQ,