日期:2014-05-16  浏览次数:20389 次

高手来看看,有什么办法能这样即时显示总价?
不用什么AJAX.
如果打勾就在总价里相加并显示??
在经典上没人回.
http://bbs.blueidea.com/attachments/2007/8/10/20070810_c525bb5a1312feedbdcfqnMnVIWyhWPs.jpg




------解决方案--------------------
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> new page </title>
<script>
function a(obj){
if(obj.firstChild.checked){
document.all.heji.value=parseInt(document.all.heji.value)+parseInt(obj.lastChild.innerText);
}else{
document.all.heji.value=parseInt(document.all.heji.value)-parseInt(obj.lastChild.innerText);
}
}
</script>
</head>
<body>
<span> 订购价格 </span> <br>
<span onclick= "a(this) "> <input type=checkbox> <span> 199 </span> </span> <br>
<span onclick= "a(this) "> <input type=checkbox> <span> 299 </span> </span> <br>
<span onclick= "a(this) "> <input type=checkbox> <span> 399 </span> </span> <br>
<span onclick= "a(this) "> <input type=checkbox> <span> 499 </span> </span> <br>
<span> 合计 </span> <input type=text id=heji value= "0 ">
</body>
</html>
------解决方案--------------------
onclick=\ "OnClick_Chk(obj)

然后用一个循环将选中的累加
for(var i=0;i <objs.length;i++) {
if(objs[i].checked) {
try {
money1 = objs[i].value;//前提是控件绑定的是价格
money1 = parseFloat(money1);
......... money1 = money1 + money1;
}
catch(e){} } }
lable.innerText = money1;
}我是这样做的,不是复选框绑定价格
------解决方案--------------------
<!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>
<title> total </title>
<script language= "javascript " type= "text/javascript ">
window.onload = function ()
{
chks = document.getElementById( "price ").childNodes;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].type == "checkbox ")
{
chks[i].attachEvent( "onclick ", calPrice);
}
}
}
function calPrice()
{
var strTotal = document.getElementById( "txtTotal ").value;
var curTotal = strTotal == " " ? 0 : parseFloat(strTotal);
var chk = event.srcElement;
if (chk.checked)// 选中则相加
{
curTotal += parseFloat(chk.value);
}
else// 不选中则相减
{
curTotal -= parseFloat(chk.value);
}
document.getElementById( "txtTotal ").value = curTotal;
}
</script>
</head>
<body>
<div id= "price ">
<input type= "checkbox " id= "ch1 " value= "199 " /> 199
<input type= "checkbox " id= "ch2 " value= "299 " /> 299
</div>
总价: <input type= "text " id= &q