Javascript实时做减法



我正在做一个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: &nbsp;
                <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>                       

这是一张说明性图片

检查您的函数是否正确启动,您是否正在使用$(document).ready?此外,您可能还想尝试将this.val()替换为$(this).val()

最新更新