如何实现点击单选框时,把三个数字进行相加
HTML code
<html>
<head>
<table>
<td><INPUT id=shipping_2 name=deliveryid value="15" type=radio checked="checked">普通快递</Td>
<Td><INPUT id=shipping_2 name=deliveryid value="20" type=radio >顺丰快递 </Td>
<Td><INPUT id=shipping_2 name=deliveryid value="30" type=radio >货到付款</Td>
</table>
<div id="amountInfo">
<div class='clearfix'>
<table width="100%" cellpadding="0" cellspacing="0" class="liststyle data">
<tr>
<th>商品总价格:</th> <td class="price">¥65.8</td>
</tr>
<tr>
<th>运费:</th> <td class="price">¥15.0</td>
</tr>
<tr>
<th>订单总金额:</th> <td><span class="price1">¥80.8</span></td>
</tr>
</table>
</div>
</div>
</head>
</html>
如上源码:我有三个单选框,单选框里都有一个数值,分别为15,20,30.如果实现,当点击单选框时触发,把运费后面的15.0换成单选框的值,把订单总额计算成商品总额+运费,并显示在订单总金额后面。
------解决方案--------------------<html>
<head>
<script type="text/javascript" language="javascript">
function sum(money){
document.getElementById('id2').innerHTML = "¥"+money;
var spjg = document.getElementById('id1').innerHTML.replace("¥","");
document.getElementById('id3').innerHTML="¥"+spjg*1+money*1;
}
</script>
</head>
<body>
<table>
<td><INPUT id=shipping_2 name=deliveryid value="15" type=radio checked="checked" onClick="sum(this.value)">普通快递</Td>
<Td><INPUT id=shipping_2 name=deliveryid value="20" type=radio onClick="sum(this.value)">顺丰快递 </Td>
<Td><INPUT id=shipping_2 name=deliveryid value="30" type=radio onClick="sum(this.value)">货到付款</Td>
</table>
<div id="amountInfo">
<div class='clearfix'>
<table width="100%" cellpadding="0" cellspacing="0" class="liststyle data">
<tr>
<th>商品总价格:</th> <td id="id1" class="price">¥65.8</td>
</tr>
<tr>
<th>运费:</th> <td id="id2" class="price">¥15.0</td>
</tr>
<tr>
<th>订单总金额:</th> <td><span id="id3" class="price1">¥80.8</span></td>
</tr>
</table>
</div>
</div>
</body>
</html>
------解决方案--------------------document.getElementById('id3').innerHTML="¥"+(spjg*1+money*1);
这句改一下,忘了加括号。