建立一个利率计算器,但是不会产生数字 [英] Building an interest rate calculator, however it won't produce figure
本文介绍了建立一个利率计算器,但是不会产生数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试构建一个计算器,该计算器可以在单击按钮时根据利率计算每月付款,我使用的是基本的JavaScript引导程序。我已经通过一些答案和问题解决了一些错误,但我的计算器仍然无法得出数字。
I am building trying to build a calculator that calculates a monthly payment based on an interest rate when clicking on a button, I'm using basic javascript bootstrap. I have already been through some answers and questions ironed out some bugs but my calculator still won't produce a figure. Could someone help?
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;}
推荐答案
只需在调用 document.getElementById( pp)。value()
$ b时删除()
$ b as
Just remove ()
while calling document.getElementById("pp").value()
as
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
不是函数。
这是链接到工作的插栓
value
is not a function.
Here is a link to a working plunker
这篇关于建立一个利率计算器,但是不会产生数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文