您的Javascript必须遵循以下准则:
- 如果收入为70,000美元或以上,税率从70%开始(%符号不会显示)
- 如果收入是20,000美元或以下,税率从10%开始(%符号不会显示)
- 否则税率从25%开始
醇>
我知道可能有1000个错误,但任何有助于我解决这个问题的事情都会有所帮助
我的功能不起作用,我很确定我甚至不在正确的轨道上
<html>
<head>
<script language = "JavaScript">
function ()
{
var IncomeInput,
TaxRateCalc;
IncomeInput = parseInt(document.TaxInfo.Income.value);
if (IncomeInput>=70000)
{
TaxRateCalc = "70";
}
else if (IncomeInput=<20000)
{
TaxRateCalc = "10";
}
else ()
{
TaxRateCalc = "25";
}
document.TaxInfo.TaxRate.value = TaxRateCalc;
}
</script>
</head>
<body>
<center>
The Taxman
</center>
<form name = "TaxInfo">
<table border = "3">
Your Tax Information<br>
<tr><td>Income</td> <td> <input name = "Income" value = "10000000" size = "20"> </td> </tr>
<tr><td>RRSP</td> <td> <input name = "RRSP" value ="0" size = "20"></td> </tr>
<tr><td>Tax Rate</td> <td> <input name = "TaxRate" value = "" size = "20"> </td> </tr>
<tr><td>Taxes Paid</td> <td> <input name = "TaxesPaid" value = "0" size = "20"> </td> </tr>
<tr><td>Refund or Due</td> <td> <input name = "RefundOrDue" value = "0"size = "20"> </td> </tr>
</table>
</form>
<form name = "Extra Deductions">
Extra Deductions-
Children <input name = "Children" type = "radio">
Spouse <input name = "Spouse" type = "radio">
Both <input name = "Both" type = "radio">
None <input name = "None" checked type = "radio">
</form>
<form name = OldPeople >
Over age 65? <input name = "Over age 65?" type = "checkbox" >
</form>
<form name = "Selection">
Special Cases
<select name="SpecialCases">
<option value ="None"> None </option>
<option value ="Hardship Claimed"> Hardship Claimed </option>
<option value ="Mercy"> Mercy </option>
<option value ="Lawyer"> Lawyer </option>
</select>
</form>
<form name = "buttons">
<input type = "button" value = "Calculate your tax" onclick = "">
<input type = "button" value = "Clear Display Area" onclick= "aloop">
</form>
<form name = "YourTaxRate">
Your Tax Rate<br> <textarea name = "TaxRate" rows = "15" cols = "25"> </textarea>
</form>
</body>
</html>
答案 0 :(得分:0)
我想知道有多少是模板。顺便说一下,对自己有信心。我不知道你自己写了多少,但对于函数本身,只需要切换IncomeInput<=20000
比较器。
<html>
<head>
</head>
<body>
<script>
function calcTax() {
var IncomeInput, TaxRateCalc;
IncomeInput = parseInt(document.TaxInfo.Income.value);
if (IncomeInput>=70000)
{
TaxRateCalc = "70";
}
else if (IncomeInput<=20000)
{
TaxRateCalc = "10";
}
else
{
TaxRateCalc = "25";
}
document.YourTaxRate.TaxRate.value = TaxRateCalc;
}
</script>
<center>
The Taxman
</center>
<form name = "TaxInfo">
<table border = "3">
Your Tax Information<br>
<tr><td>Income</td> <td> <input name = "Income" value = "10000000" size = "20"> </td> </tr>
<tr><td>RRSP</td> <td> <input name = "RRSP" value ="0" size = "20"></td> </tr>
<tr><td>Tax Rate</td> <td> <input name = "TaxRate" value = "" size = "20"> </td> </tr>
<tr><td>Taxes Paid</td> <td> <input name = "TaxesPaid" value = "0" size = "20"> </td> </tr>
<tr><td>Refund or Due</td> <td> <input name = "RefundOrDue" value = "0"size = "20"> </td> </tr>
</table>
</form>
<form name = "Extra Deductions">
Extra Deductions-
Children <input name = "Children" type = "radio">
Spouse <input name = "Spouse" type = "radio">
Both <input name = "Both" type = "radio">
None <input name = "None" checked type = "radio">
</form>
<form name = "OldPeople" >
Over age 65? <input name = "Over age 65?" type = "checkbox" >
</form>
<form name = "Selection">
Special Cases
<select name="SpecialCases">
<option value ="None"> None </option>
<option value ="Hardship Claimed"> Hardship Claimed </option>
<option value ="Mercy"> Mercy </option>
<option value ="Lawyer"> Lawyer </option>
</select>
</form>
<form name = "buttons">
<input type = "button" value = "Calculate your tax!" onclick = "calcTax()" />
<input type = "button" value = "Clear Display Area" onclick = "" />
</form>
<form name = "YourTaxRate">
Your Tax Rate<br> <textarea name = "TaxRate" rows = "15" cols = "25"> </textarea>
</form>
</body>
</html>
答案 1 :(得分:0)
试试这个:
function myFunction() {
var income = document.getElementById("income").value;
var taxRateCalc;
if (income == "") {
alert("Please type a valid income.");
} else {
if (income >= 70000) {
taxRateCalc = "70";
}
else if (income <= 20000) {
taxRateCalc = "10";
}
else {
taxRateCalc = "25";
}
document.getElementById("taxRate").value = taxRateCalc;
}
}
&#13;
Income: <input type="text" id="income">
<button onclick="myFunction()">Validate Income</button><br><br>
Tax Rate: <input type="text" id="taxRate" readonly>
&#13;