① 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了。