<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>

解决方案 »

  1.   

    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;
    }我是这样做的,不是复选框绑定价格
      

  2.   

    楼上的代码行,但不是我想要的取得复选框的值..
    笨笨猪给个调用的例子???
    我这样不行:
    <form id=form1>
    订购价格</span><br/>
    <input name="chkProds" type=checkbox id="chkProds" value="199"  onClick=" OnInit_Info()">
    199<br/>
    <input name="chkProds" type=checkbox id="chkProds" value="299" onClick=" OnInit_Info()">
    <span>299</span><br/>
    <input name="chkProds" type=checkbox id="chkProds" onClick=" OnInit_Info()" value="399">
    <span>399</span><br/>
    <input name="chkProds" type=checkbox id="chkProds" onClick=" OnInit_Info()" value="499">
    <span>499</span><br/>
    <span>合计</span><input name="lable2" type=text id=lable2 value="0">
    </form>
      

  3.   

    <!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="txtTotal"/>
    </body>
    </html>