js输入的表单什么的都是字符串,需要函数parseFloat转化,切记

实例程序

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>java上机题目</title>
<style type="text/css">
#foot{
background-color: yellow;
}
caption{
font-style: italic;
font-size: 15px;
}
</style>
<script language="JavaScript" type="text/javascript">
function  $(a)
{
var $b=document.getElementById(a);
return $b;
}
function myFunction()
{   
$("34").innerHTML=((parseFloat($("33").value)+parseFloat($("32").value))/2);
$("44").innerHTML=((parseFloat($("43").value)+parseFloat($("42").value))/2);
   $("52").innerHTML=((parseFloat($("32").value)+parseFloat($("42").value))/2);
   $("53").innerHTML=((parseFloat($("43").value)+parseFloat($("33").value))/2);
   $("54").innerHTML=((parseFloat($("44").innerHTML)+parseFloat($("34").innerHTML))/2);

}
</script>
</head>
<body>
<table border="1" cellpadding="1">
<caption>组合表格</caption>
<tr> 
<th rowspan="2"></th>
<th colspan="2" >Points</th>
<th rowspan="2">Personal Average</th>
</tr>
   <tr>
    <th>Test1</th>
    <th>Test2</th>
   </tr>
   <tr>
    <th>English</th>
    <td ><input type="text" size="20px" id="32"value=""></td>
    <td ><input type="text" size="20px" id="33" value=""></td>
    <td id="34"></td>
   </tr>
   <tr>
    <th>Math</th>
    <td ><input type="text" size="20px" id="42" value=""></td>
    <td ><input type="text" size="20px" id="43" value=""></td>
    <td id="44"></td>
   </tr>
   <tr id="foot">
    <th>Average</th>
    <td id="52"></td>
    <td id="53"></td>
    <td id="54"></td>
   </tr>
   
</table>
<input type="button" οnclick="myFunction()" value="计算">
</body>
</html>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值