我正在构建一个计算器,根据点击按钮计算每月付款的计算器,我正在使用基本的javascript引导程序。我已经通过一些答案和问题解决了一些错误,但我的计算器仍然不会产生数字。有人可以帮忙吗?
HTML:
<div class="row text-muted">
<div class="col-md-5 col-md-offset-1 calc-input">
<h3>Purchase Price</h3>
<div class="input-group">
<span class="input-group-addon">£</span>
<input type="text" class="form-control" id="pp" placeholder="150,000">
</div>
</div>
<div class="col-md-5 calc-input">
<h3>Deposit</h3>
<div class="input-group">
<input type="text" class="form-control" placeholder="10">
<span class="input-group-addon">%</span>
</div>
<div class="input-group">
<span class="input-group-addon">£</span>
<input type="text" class="form-control" id="dp" placeholder="15,000">
</div>
</div>
</div>
<div class="row text-muted">
<div class="col-md-5 col-md-offset-1">
<div class="input-group">
<input type="text" class="form-control" id="mt" placeholder="25">
<span class="input-group-addon">Years</span>
</div>
</div>
<div class="col-md-5">
<div class="input-group">
<input type="text" class="form-control" id="ir" placeholder="4">
<span class="input-group-addon">%</span>
</div>
</div>
</div>
<div class="row text-muted">
<div class="col-md-10 col-md-offset-1 text-center">
<button type="submit" class="btn btn-cta" onclick="calculate()">Calculate</button>
<h3>Estimated Monthly Payment:</h3>
<p id="result"></p>
</div>
</div>
这是JS:
function calculate() {
var pp = document.getElementById("pp").value();
var dp = document.getElementById("dp").value();
var mt = document.getElementById("mt").value();
var ir = document.getElementById("ir").value();
var result = document.getElementById("result");
var la = pp - dp;
var intRate = (ir/100)/12;
var months = mt * 12;
var monthlyPayment = ((((la*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100).toFixed(2));
result.innerHTML = monthlyPayment;}
答案 0 :(得分:2)
在调用()
时移除document.getElementById("pp").value()
如
var pp = document.getElementById("pp").value;
var dp = document.getElementById("dp").value;
var mt = document.getElementById("mt").value;
var ir = document.getElementById("ir").value;
value
不是一个功能。
这是一个link到一个工作的plunker