1 回答
TA贡献1833条经验 获得超4个赞
$(function() {
$("#payment").on("keydown keyup", sum);
function sum() {
var balance=Number.parseFloat(document.getElementById('balance').value);
var payment = Number.parseFloat(document.getElementById('payment').value);
var amount = Number.parseFloat(document.getElementById('amount').value);
if (payment>=amount) {
document.getElementById('tbalance').value=balance;
}
else if(payment<amount){
TotalBalance = balance+ (amount - payment);
document.getElementById('tbalance').value=TotalBalance;
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-md-2">
Amount<input type="text" name="amount" id="amount" class="form-control" />
</div>
<div class="col-md-2">
Cash Tendered </strong>: <input type="text" name="payment" id="payment" class="form-control" />
</div>
<div class="col-md-2">
Balance</strong>: <input type="text" name="balance" id="balance"readonly="" class="form-control" value="40"/>
</div>
<div class="col-md-2">
TOtalBalance</strong>: <input type="text" name="tbalance" id="tbalance"readonly="" class="form-control" value="40" />
</div>
- 1 回答
- 0 关注
- 60 浏览
添加回答
举报