【发布时间】:2014-09-10 08:42:03
【问题描述】:
这里我有一些表单组,其中包含来自数据库的值
<div class="form-group">
<label for="exampleInputTotalBayar">Total Bayar</label>
<input type="text" class="form-control" id="inputTotalBayar" placeholder="Total Bayar" name="totalBayar" value="{{ $peminjaman->totalBayar }}">
</div>
<div class="form-group">
<label for="exampleInputJumlahBayar">Jumlah Bayar</label>
<input type="text" class="form-control" id="inputJumlahBayar" onchange="" placeholder="Jumlah Bayar" name="jumlahBayar" value="{{ $peminjaman->jml_bayar }}">
</div>
然后我想以这种形式给出新的值
<div class="form-group">
<label for="exampleInputDenda">Denda</label>
<input type="text" class="form-control" id="exampleInputDenda" placeholder="Denda" name="denda" value="{{ $peminjaman->denda }}">
</div>
所以,当我在表单组 Denda 中给出新值时,输出将显示在此处
<p>Bayar Pengembalian: <div id="bayar" name="bayar"></div></p>
我的javascript代码是这样的
<script type="text/javascript">
var bayar = parseInt("0");
var totalBayar = parseInt($("#inputTotalBayar").val());
var jumlahBayar = parseInt($("#inputJumlahBayar").val());
var denda = parseInt($("#exampleInputDenda").val());
$("#exampleInputDenda").change(function() {
bayar = bayar + denda + totalBayar - jumlahBayar;
$("#bayar").html(bayar);
});
但是没有出现计算结果,你能帮我解决这个问题吗?
【问题讨论】:
-
我发现在 SO 中永远不应该问这个问题......在网上快速搜索足以确定如何执行类型转换......
-
把你的变量初始化放在你的函数里面。
标签: javascript string int