我试图让 Javascript 计算几个不同变量和结果的函数。老实说,我在过去的两天里一直在努力,实际上不知道从这里去哪里。我的代码如下:
<html>
<title>Calculate Your Monthly Payments</title>
<script language = "JavaScript">
function Calc(){
var a, res;
a = parseFloat(document.monthly.form.value);
res1 = a/1000;
res2 = a/500;
res3 = a/300;
if(document.monthly.payments[1].style.visibility = "visible" )
window.alert("Your monthly repayments have been estimaded to be £" + res1);
else if(document.monthly.payments[2].style.visibility = "visible" )
window.alert("Your monthly repayments have been estimaded to be £ " + res2);
else(document.monthly.payments[3].style.visibility = "visible" )
window.alert("Your monthly repayments have been estimaded to be £ " + res3);
}
</script>
</head>
<div id="container">
<h2>Calculate Your Monthly Payments</h2>
<h4>Please fill in the form below</h4>
<form name = "monthly">
How much are you borrowing? (£): <br><input name = "form" type = "text" size = 10 id="textarea"> <br><br>
Mortgage Type: <br>
<select name = "payments">
<option value="" selected>Please Select </option>
<option value="1">Mortgage 2.19% fixed until 2015 </option>
<option value="2">Mortgage 3.17% fixed until 2017 </option>
<option value="3">Mortgage 3.18% fixed until 2024 </option>
</select>
<br><br>
<input type = "button" value = "Calculate Payments! " onclick = "Calc();">
</form>
</div>
</html>
我一直试图将事件显示为一个弹出窗口,上面写着
“您的每月付款是......”。
我要实现的方程式应该可以作为您输入的内容除以您选择的内容。
如果选择a,则作为示例,它将被除以1000
,如果选择b,则作为示例,它将被除以500
,如果选择c,则作为示例,它将被除以300。
但是..这些都不起作用。
我一直在一遍又一遍地检查代码并使其工作,尽管只是部分地因为事件然后显示两个弹出窗口。首先是选项值 1,然后在单击选项值 2 后替换它。
问题是:
在浏览器中查看并单击“计算付款”按钮后,没有任何反应。为什么是这样?
我希望我能说清楚,因为我对英语有点粗鲁,但我会很感激任何帮助。