JavaScript里如何在提交表单后获取被选择的单选按钮的值的总和? 图示如下
1个回答
展开全部
觉得你应该是要这个效果。。。祝你好运,希望对你有帮助!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>评教系统</title>
<style type="text/css">
#eval td{text-align:center;}
</style>
</head>
<body>
<table id="eval" width="600" border="1">
<tr>
<th colspan="4">评价等级</th>
</tr>
<tr>
<td>优 2.0</td>
<td>良 1.5</td>
<td>中 1.0</td>
<td>差 0.5</td>
</tr>
<tr>
<td><input type="radio" name="row1" value="2"></td>
<td><input type="radio" name="row1" value="1.5"></td>
<td><input type="radio" name="row1" value="1"></td>
<td><input type="radio" name="row1" value="0.5"></td>
</tr>
<tr>
<td><input type="radio" name="row2" value="2"></td>
<td><input type="radio" name="row2" value="1.5"></td>
<td><input type="radio" name="row2" value="1"></td>
<td><input type="radio" name="row2" value="0.5"></td>
</tr>
<tr>
<td><input type="radio" name="row3" value="2"></td>
<td><input type="radio" name="row3" value="1.5"></td>
<td><input type="radio" name="row3" value="1"></td>
<td><input type="radio" name="row3" value="0.5"></td>
</tr>
<tr>
<td><input type="radio" name="row4" value="2"></td>
<td><input type="radio" name="row4" value="1.5"></td>
<td><input type="radio" name="row4" value="1"></td>
<td><input type="radio" name="row4" value="0.5"></td>
</tr>
</table>
<input type="button" id="sub" value="提交">
<script type="text/javascript">
(function(){
document.getElementById("sub").onclick = function(){
var r = document.getElementById("eval").getElementsByTagName("input");
var sum = 0;
var len = r.length;
for(var i = 0; i < len; i++){
if(r[i].checked){
sum += parseFloat(r[i].value);
}
}
alert("评教总分:" + sum + "分");
}
})();
</script>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>评教系统</title>
<style type="text/css">
#eval td{text-align:center;}
</style>
</head>
<body>
<table id="eval" width="600" border="1">
<tr>
<th colspan="4">评价等级</th>
</tr>
<tr>
<td>优 2.0</td>
<td>良 1.5</td>
<td>中 1.0</td>
<td>差 0.5</td>
</tr>
<tr>
<td><input type="radio" name="row1" value="2"></td>
<td><input type="radio" name="row1" value="1.5"></td>
<td><input type="radio" name="row1" value="1"></td>
<td><input type="radio" name="row1" value="0.5"></td>
</tr>
<tr>
<td><input type="radio" name="row2" value="2"></td>
<td><input type="radio" name="row2" value="1.5"></td>
<td><input type="radio" name="row2" value="1"></td>
<td><input type="radio" name="row2" value="0.5"></td>
</tr>
<tr>
<td><input type="radio" name="row3" value="2"></td>
<td><input type="radio" name="row3" value="1.5"></td>
<td><input type="radio" name="row3" value="1"></td>
<td><input type="radio" name="row3" value="0.5"></td>
</tr>
<tr>
<td><input type="radio" name="row4" value="2"></td>
<td><input type="radio" name="row4" value="1.5"></td>
<td><input type="radio" name="row4" value="1"></td>
<td><input type="radio" name="row4" value="0.5"></td>
</tr>
</table>
<input type="button" id="sub" value="提交">
<script type="text/javascript">
(function(){
document.getElementById("sub").onclick = function(){
var r = document.getElementById("eval").getElementsByTagName("input");
var sum = 0;
var len = r.length;
for(var i = 0; i < len; i++){
if(r[i].checked){
sum += parseFloat(r[i].value);
}
}
alert("评教总分:" + sum + "分");
}
})();
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询