我正在开发一个POS项目,在手动添加客户提供的金额后,我需要实时减法。我不确定我的代码出了什么问题,所以请一点帮助。
<div class="sidebar-category">
<div class="category-content" style="padding: 8px">
<div class="row">
<div class="col-sm-6">
<input id="client_paid" type="text" placeholder="Paguar" class="form-control" >
<br>
<input id="change" type="text" placeholder="Resto" class="form-control change">
</div>
<div class="col-sm-6">
<h6 class="text-semibold text-right no-margin-top">Totali: <span id = "all-products-subtotal"> {{Session::get('all_products_subtotal') ? number_format(Session::get('all_products_subtotal'),2,",","."):'0'}} </span> </h6>
<ul class="list list-unstyled text-right">
Status:
<a href="#" class="label bg-success-400 dropdown-toggle" data-toggle="dropdown">Online</a>
</ul>
</div>
</div>
</div>
</div>
这个脚本:
<script>
$("#client_paid").keyup(function(){
var client_paid = this.val();
var total ={{Session::get('all_products_subtotal') ? number_format(Session::get('all_products_subtotal'),2,",","."):'0'}};
if(client_paid >= total){
var change = client_paid - total;
$("#change").val(change);
}
});
</script>
答案 0 :(得分:1)
检查您的功能是否正常启动,是否使用$(document).ready
?您也可以尝试将this.val()
替换为$(this).val()