一直在爲此HTML5作品使用Javascript,但我無法獲得美聯儲稅或毛總額正確提示。我認爲這可能與我的單選按鈕有關。任何幫助將是美好的。我對此很陌生,所以請儘量以通俗的語言保留答案。使用單選按鈕計算Javascript/HTML5的麻煩
<!HTML>
<html>
<head>
<title> Payroll Calculator </title>
<script language="javascript">
function Calc()
{
var hour, pay, status, kids, gross, tax, net;
hour = parseFloat(document.payroll.Hours.value);
pay = parseFloat(document.payroll.PayRate.value);
gross = parseFloat (hour * pay);
document.payroll.GrossPay.value = gross.toFixed(2);
kids = parseFloat(document.payroll.Dependents.value);
status = parseFloat(document.payroll.Marital.value);
tax = parseFloat (gross * status) - kids;
document.payroll.FedTaxes.value = tax.toFixed(2);
net = parseFloat (gross - tax);
document.payroll.NetPay.value = net.toFixed(2);
}
</script>
</head>
<body>
<form name="payroll">
<table bgcolor="grey" cellpadding="0">
<tr><td colspan="2" align="center"><b>Payroll Calculator<b></td></tr>
<tr><td><label for="name"> Name: </label></td>
<td><input type="text" name="name"></td></tr>
<tr><td><label for="Hours"> Hours: </label></td>
<td><input type="text" name="Hours"> 99.9 </td></tr>
<tr><td><label for="PayRate"> Pay Rate: </label></td>
<td><input type="text" name="PayRate"> 99.99 </td></tr>
<tr><td colspan="2"> Marital Status:
<input type="radio" value=".30" name="Marital" checked> Single
<input type="radio" value=".20" name="Marital"> Married </td></tr>
<tr><td> Dependents: </td><td>
<select name="Dependents">
<option value="10"> 1 </option>
<option value="20"> 2 </option>
<option value="30"> 3 </option>
<option value="40"> 4 </option>
<option value="50"> 5 </option>
</select></td></tr>
<tr><td><label for="GrossPay"> Gross Pay: </label></td>
<td><input type="text" name="GrossPay" readonly></td></tr>
<tr><td><label for="FedTaxes"> Fed Taxes: </label></td>
<td><input type="text" name="FedTaxes" readonly></td></tr>
<tr><td><label for="NetPay"> Net Pay: </label></td>
<td><input type="text" name="NetPay" readonly></td></tr>
<tr><td colspan="2" align="center"><input type="button" value="Calculate" onclick="Calc()">
<input type="reset" value="Clear"></td></tr>
</form>
</table>
</body>
</html>
''標籤在''標籤之前。需要相反。 – Papa
好點謝謝! – JoswaR