我的代码存在一些问题,我正在创建一个网站来计算抵押贷款的首付: 前25,000美元的3% 确保需要首付的住房抵押贷款如下: 前25,000美元的3% 其余5%
输入包括SSN和抵押金额。我希望它打印申请人的SSN和所需的首付金额。拒绝任何超过70,000美元的申请。不要忘记验证您的输入。如果输入不好,我希望它显示错误信息并再次询问输入数据。
<html>
<head>
<title>Mortgage Charges</title>
<script type="text/javascript">
// Program name: FHA
// Purpose: print the applicant’s SSN and the amount of down payment required
// Date last modified: 3/29/12
function mortgage() {
var amtOwed = parseInt(document.frmOne.ssn.value);
var mortgage = 0;
if (mortgage <= 25000) {
amtOwed = 0;
}
else if (mortgage >= 5%) {
}
alert(amtOwed);
document.frmOne.mortage.value = amtOwed;
}
window.onload = function() {
document.frmOne.onsubmit = function(e) {
mortgage();
return false;
};
};
</script>
</head>
<body>
<form name="frmOne">
Enter your SSN:<input type="text" id="ssn" /><br />
Mortgage amount:<input type="text" id="mortage" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
答案 0 :(得分:1)
我恐怕无法理解你的逻辑。你觉得这个怎么样?
让我分解您当前代码的作用:
function mortgage() {
var amtOwed = parseInt(document.frmOne.ssn.value);
// Get the value from the text box, and convert it to a number. That's good.
var mortgage = 0;
// Initialise a variable. Fair enough.
if (mortgage <= 25000) {
// You JUST set morgage=0. How can it be anything but less than 25k?
amtOwed = 0;
// You are overwriting the value you got from the form with 0
}
else if (mortgage >= 5%) {
// Okay, first of all this else will never be reached, see comment above.
// Second... 5% of what, exactly? If you want 5% of a number, multiply the number by 0.05
// Third, what's the point of this block if there's no code in it?
}
alert(amtOwed);
document.frmOne.mortage.value = amtOwed;
}
基本上,您的代码可以简化为:
function morgage() {document.frmOne.mortage.value = 0;}
因为就是这样。
我并不完全明白你在做什么,但希望能够解释你当前的尝试会帮助你找到答案。