html网页调用js中getAvg()和getTotal()函数怎么写
发布网友
发布时间:2023-06-01 12:44
我来回答
共2个回答
热心网友
时间:2024-11-23 05:06
希望可以帮到你
<!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>3</title>
</head>
<body>
<tr>
<td height="12"><div align="center">语文</div></td>
<td height="12"><div align="center">
<input type="text" id="txtchinese" />
</div></td><td height="12"><div align="center">数学</div></td>
<td height="12"><div align="center">
<input type="text" id="txtmath" />
</div></td><td height="12"><div align="center">英语</div></td>
<td height="12"><div align="center">
<input type="text" id="txtEnglish" />
</div></td>
</tr>
<tr>
<td height="12"><div align="center">
<label>
<input type="submit" name="Submit" value="总成绩" onclick="getTotal()"/>
</label>
</div></td>
<td height="12"><div align="center">
<input type="text" id="txtTotal" />
</div></td>
</tr>
<tr>
<td height="12"><div align="center">
<label>
<input type="submit" name="Submit2" value="平均分" onclick="getAvg()" />
</label>
</div></td>
<td height="12"><div align="center">
<input type="text" id="txtAvg" />
</div></td>
</tr>
<script type="text/javascript">
function getTotal(){
var ch = document.getElementById("txtchinese").value;
var en = document.getElementById("txtEnglish").value;
var ma = document.getElementById("txtmath").value;
var total = Number(ch) + Number(en) + Number(ma);
var avg = total/3;
document.getElementById("txtTotal").value = total;
//document.getElementById("txtAvg").value = avg;
}
function getAvg(){
var ch = document.getElementById("txtchinese").value;
var en = document.getElementById("txtEnglish").value;
var ma = document.getElementById("txtmath").value;
var total = Number(ch) + Number(en) + Number(ma);
var avg = total/3;
//document.getElementById("txtTotal").value = total;
document.getElementById("txtAvg").value = avg;
}
</script>
</body>
</html>
热心网友
时间:2024-11-23 05:07
<script>
function getAvg(){
//得到对象的值
}
</script>追问我想知道方法中具体怎么写的,在如何把值赋值到input中???