① JS怎么实现checkbox选中后的值累加
我个你写个意思,你自己套用你的专程序
<script>
function sum_val(){
var sum = 0;
var t = document.getElementsByTagName('input');
if ( t.length == 0 ) return;
var m = t.length;
for ( var i=0; i<m; i++ ){
if ( t[i].id !属='' ){
sum += parseInt(t[i].id);
}
}
document.getElementById('sum').innerHTML = sum;
}
</script>
<input type="checkbox" id="200" />
<input type="checkbox" id="300" />
<input type="button" value="sub" onclick='sum_val()' />
② 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>
试试看,还有问题就给我在网络里留言!
③ 初学JavaScript,checkbox勾选计算和值并显示
<html>
<head>
<title>checkbox项的自动计算</title>
<script type="text/javascript">
var val = 0;
function calc(obj){
val += parseInt(obj.value);
document.getElementById('total').value = val;
}
</script>
</head>
<body bgcolor="#FFffFF">
<center>
<h2>合计金额计算</h2>
</center>
<br>
<form name="calcFORM">
<input type="checkbox" value="200" onClick="calc(this)">商品【200元】<br>
<input type="checkbox" value="130" onClick="calc(this)">商品2【130元】<br>
<input type="checkbox" value="530" onClick="calc(this)">商品3【530元】<br>
<input type="checkbox" value="30" onClick="calc(this)">商品4【30元】<br>
<br>
<input type="checkbox" value="1200" onClick="calc(this)">商品5【1200元】<br>
<input type="checkbox" value="2300" onClick="calc(this)">商品6【2300元】<br>
<input type="checkbox" value="3100" onClick="calc(this)">商品7【3100元】<br>
<br>
合计金额:<input id="total" type="text" name="total">
</form>
</body>
</html>
④ JSP中怎么从checkbox获得值并相加计算结果
我做的购物车的部分servlet代码:
String [] name=request.getParameterValues("fruit");
String [] price=request.getParameterValues("price");
String [] weight=request.getParameterValues("weight");
HttpSession session = request.getSession();
ShoppingCart cart=(ShoppingCart)session.getAttribute("shoppingCart");
if(cart == null) {
cart = new ShoppingCart();
session.setAttribute("shoppingCart", cart);
}
int j=0;
for(int i=0;i<name.length&&j<weight.length;i++,j++){
for(int k=0;k<weight.length;k++){
if(name[i].length()==0||weight[j].length()==0){
j++;
}else break;
}
name[i]=new String(name[i].getBytes("iso8859-1"),"gb2312");
cart.addItem(name[i],price[j],weight[j]);
}
购物车页面部分代码:
<%
ShoppingCart cart = (ShoppingCart)session.getAttribute("shoppingCart");
List items=cart.getItemsOrdered();
double sumMoney=0;
for(int i=0;i<items.size();i++){
ItemOrder order = (ItemOrder)items.get(i);
double money=order.getPrice()*order.getZhongliang();
sumMoney+=money;
%>
<tr>
<td><%=order.getName()%></td>
<td><%=order.getPrice()%></td>
<td><%=order.getZhongliang() %></td>
<td><%=money%></td>
</tr>
<%
}
%>
<tr>
<td><font color=red size=4>合计:<%=sumMoney%>元</font></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan=4></td>
</tr>
<tr>
<td colspan=4>
<input type="button" value="确 定" onClick="alert('谢谢使用!祝您愉快!')"><a href="shopping.jsp">返回继续选购</a>
</td>
⑤ asp.net中如何实现根据前面选的复选框而得到勾选复选框所有计算出来的价格总计
就5分啊真小气!!!
给你个思路:你可以写一个循环。当checkbox勾选时,总版计+=小计。
我这个用Jquery写的(没权有循环)。代码:
$("input[name='qx']:checked").each(function () {
string += this.value;
})//this.value是勾选列的钱,如果你是用repeater绑的话,那就把这个字段在checkbox这里也绑下就OK
这里的“qx”是checkbox 的name和id。
⑥ php购物车结算总价格问题
两种办法:
1. 在foreach($dat as $tool)代码段里,设置累加器,进行价格的总价计算。
2. 使用SQL语句,再查询出某ID的总价。
⑦ js如何获取购物车中选中的checkbox的值并返回给php-CSDN论坛
$("input[type=checkbox]").val() 然后通过get或者post方式提交 get提交形式 xxx.action?name=value&name=value
⑧ 急急 求助JS 复选框 我选择复选框然后把价格相加 最后呈现出总价 代码如下
感觉你要的应该是这种效果,全部代码给你,jQuery的类库要用7.2以上的版本
<html>
<head>
<title>知道答案</title>
<script type="text/javascript" src='js/jquery.min.js'></script>
<script type="text/javascript">
$(function(){
$(".text_box").click(function(){
var val=0;
$("[class='text_box']:checked").each(function(){
val+=parseInt($(this).val());
//alert(val);
})
$("#dd").val(val);
});
})
</script>
</head>
<body>
<input type="button" id="btn" value="获得选中的所有值">
<br>
<input type="checkbox" class="text_box" value='3' />3<br>
<input type="checkbox" class="text_box" value='4' />4<br>
<input type="checkbox" class="text_box" value='5' />5<br>
<input type="checkbox" class="text_box" value='6' />6<br>
<input type="text" id="dd" value=''/>
</body>
</html>
⑨ 购物车功能 点击一个 checkbox 将这一行的所有数据返回到后端 其中js写的商品数量和商品价格总和怎么传
foreach有varStatus属性,这个就一个行id,在input上设置id,然后通过id获取他的值,在网后端发送数据不就行了
⑩ android 购物车怎么计算商品的总价
1、可以通过list.get(postion).……将每件商品的价格提取出来,再通过Double.valueof()转化为双精度浮点专数相加后,最属后转化为String就行
2、通过判断item里面的checkbox是否选中,如果选中将对应item的价格取出来然后相加赋值给总价的textview就ok了。