列表查询问题
选择了相关的checkbox后,总价格没有改变?
<script language=javascript>
function CheckSum()
{
var sum=0;
for(var i=0,i <document.form1.elements[ "writer "].length,i++)
{
if(document.form1.elements[ "writer "][i].checked)
{
sum=sum+parseInt(document.form1.elements[ "writer "][i].value);
}
}
totalprice.innerText=sum + "元 ";
}
</script>
<form action= " " method=post name=form1>
<input type= "checkbox " name=writer value= "10 " onclick= "CheckSum() "> 橡皮檫(10元) <br>
<input type= "checkbox " name=writer value= "20 " onclick= "CheckSum() "> 铅笔(20元) <br>
<input type= "checkbox " name=writer value= "30 " onclick= "CheckSum() "> 圆珠笔(30元) <br>
<input type= "checkbox " name=writer value= "40 " onclick= "CheckSum() "> 签字笔(40元) <br>
<input type= "checkbox " name=writer value= "50 " onclick= "CheckSum() "> 钢笔(50元) <br>
<input type= "submit " value= "Submit " id=submit1 name=Submit1> <br>
总价为: <span id= "totalprice "> 0元 </span>
</form>
------解决方案-------------------- <script language=javascript>
function CheckSum(cb)
{
var sum=0;
if(cb.checked)
sum=sum+parseInt(cb.value);
else
sum=sum-parseInt(cb.value);
totalprice.innerText=sum + "元 ";
}
</script>
<form action= " " method=post name=form1>
<input type= "checkbox " name=writer value= "10 " onclick= "CheckSum(this) "> 橡皮檫(10元) <br>
<input type= "checkbox " name=writer value= "20 " onclick= "CheckSum(this) "> 铅笔(20元) <br>
<input type= "checkbox " name=writer value= "30 " onclick= "CheckSum(this) "> 圆珠笔(30元) <br>
<input type= "checkbox " name=writer value= "40 " onclick= "CheckSum(this) "> 签字笔(40元) <br>
<input type= "checkbox " name=writer value= "50 " onclick= "CheckSum(this) "> 钢笔(50元) <br>
<input type= "submit " value= "Submit " id=submit1 name=Submit1> <br>
总价为: <span id= "totalprice "> 0元 </span>
</form>