<html>
<head>
<title>MyHtml2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/htmlcharset=UTF-8">
<script>
/*
*@author Caoshun
*@计算 合计费用
*/
function countMethod(){
var num=document.getElementById("num").value
var unitPrice=document.getElementById("unitPrice").value
var freight=document.getElementById("freight").value
document.getElementById("result").value=parseFloat((num*unitPrice))+parseFloat(freight)
}
</script>
</head>
<body>
<table border="1" cellpadding="1" cellspacing="1" background="#red" style="text-align: center">
<tr><td colspan="5" align="center">简易购物车</td></tr>
<tr>
<td>商品名称</td>
<td>数量(件)</td>
<td>单价(美元)</td>
<td>运费(美元)</td>
<td><input type="button" value="合计" onclick="countMethod()"></td>
</tr>
<tr>
<td>跑跑道具</td>
<td><input type="text" size="6" id="num"></td>
<td><input type="text" size="6" id="unitPrice"></td>
<td><input type="text" size="6" id="freight"></td>
<td><input type="text" size="6" id="result"></td>
</tr>
</table>
</body>
</html>
<script language='javascript'>function checkSum()
{
var sum = 0
for(var i=0i<document.form1.elements["writer"].lengthi++)
{
if(document.form1.elements["writer"][i].checked)
{
sum = sum +parseInt(document.form1.elements["writer"][i].value)
}
}
totalprice.innerText = sum +" 元"
}
</script>
<form method=post name=form1>
<input type="checkbox" name=writer value="34" onclick="checkSum()">韩国耳饰tm56(34元)<br>
<input type="checkbox" name=writer value="46" onclick="checkSum()">纯银吊坠tc34(46元)<br>
<input type="checkbox" name=writer value="30" onclick="checkSum()">黄莺手镯ta345(30元)<br>
<input type="checkbox" name=writer value="40" onclick="checkSum()">翡翠玉镯1346(40元)<br>
<input type="checkbox" name=writer value="50" onclick="checkSum()">天涯耳饰1233(50元)<br>
<br>
总价为:<span id="totalprice">0 元</span>
</form>