我有一个带有单选按钮和复选框的表单。在每个单选按钮下都有一列与该单选按钮相关的复选框。我正在寻找的是如何隐藏与该单选按钮无关的复选框。
我还在表格中建立了一些总计算。选择不同的单选按钮时,我想清除所有CKECK框并纠正总数。
这是我使用引导 cdn 的源代码。您可以复制并粘贴并加载到浏览器中。
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Calc Form</title>
<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="row">
<div class="span3" >
<div style="margin-left:20px; height:200px;" class="well">
<br />
<div id="subtotal">Sub-Total:</div>
<div id="tax">Tax:</div>
<div id="total">Total:</div><br />
</div>
</div>
<form id="quote" class="form-horizontal">
<div class="span8">
<table class="table table-condensed table-hover">
<thead>
<tr>
<th> Options</th>
<!-- Multiple Radios (inline) -->
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<th><label class="radio inline">
<input name="rad" value="444" onchange="calculateTotal()" checked="checked" type="radio">
<strong>1 YR</strong><br />
$444 </label>
</th>
<th><label class="radio inline">
<input name="rad" value="1332" onchange="calculateTotal()" checked="unchecked" type="radio">
<strong>3 YRS.</strong><br />
$1332 </label>
</th>
<th><label class="radio inline">
<input name="rad" value="2220" onchange="calculateTotal()" checked="unchecked" type="radio">
<strong>5 YRS.</strong><br />
$2220 </label>
</th>
<th><label class="radio inline">
<input name="rad" value="2995" onchange="calculateTotal()" checked="unchecked" type="radio">
<strong>ULTIMATE</strong><br />
$2995 </label>
</th>
</div>
</div>
</tr>
</thead>
<tbody>
<tr>
<td>Plus</td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-1yr" value="35" type="checkbox" onchange="calculateTotal()" >
+ $35 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-3yr" value="105" type="checkbox" onchange="calculateTotal()" >
+ $105 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-5yr" value="175" type="checkbox" onchange="calculateTotal()" >
+ $175 </label></td>
<td>FREE</td>
</tr>
<tr>
<td>Helicopter Option</td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-1yr" value="75" type="checkbox" onchange="calculateTotal()" >
+ $75 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-3yr" value="225" type="checkbox" onchange="calculateTotal()" >
+ $225 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-5yr" value="375" type="checkbox" onchange="calculateTotal()" >
+ $375 </label></td>
<td>FREE</td>
</tr>
<tr>
<td>PDD Option</td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-1yr" value="75" type="checkbox" onchange="calculateTotal()" >
+ $75 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-3yr" value="225" type="checkbox" onchange="calculateTotal()" >
+ $225 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-5yr" value="375" type="checkbox" onchange="calculateTotal()" >
+ $375 </label></td>
<td>FREE</td>
</tr>
<tr>
<td>Ground Ambulance Option</td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-1yr" value="75" type="checkbox" onchange="calculateTotal()" >
+ $75 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-3yr" value="225" type="checkbox" onchange="calculateTotal()" >
+ $225 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-5yr" value="375" type="checkbox" onchange="calculateTotal()" >
+ $375 </label></td>
<td>FREE</td>
</tr>
<tr>
<td>100 Mile Waiver Option</td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-1yr" value="95" type="checkbox" onchange="calculateTotal()" >
+ $95 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-3yr" value="285" type="checkbox" onchange="calculateTotal()" >
+ $285 </label></td>
<td><label class="checkbox">
<input name="checkboxes" class="type-group type-group-5yr" value="475" type="checkbox" onchange="calculateTotal()" >
+ $475 </label></td>
<td>FREE</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p class="text-right">
<button class="btn btn-primary">Continue>></button>
</p>
</div>
</form> </div>
<script>
function calculateTotal()
{
var subtotalField = document.getElementById("subtotal");
var mycalc = document.forms["quote"].getElementsByTagName("input");
var subtotal = 0;
var tax = 0;
var total = 0;
for (var i = 0, length = mycalc.length; i < length; i++) {
if (mycalc[i].checked) {
subtotal += parseInt(mycalc[i].value);
}
}
tax = (subtotal * .09).toFixed(2);
total = (parseFloat(subtotal) + parseFloat(tax)).toFixed(2);
document.getElementById("subtotal").innerHTML = "Sub-Total: $" + subtotal;
document.getElementById("tax").innerHTML = "Tax: $" + tax;
document.getElementById("total").innerHTML = "Total: $" + total;
};
</script>>
</body>
</html>