Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript实时进行减法_Javascript_Jquery - Fatal编程技术网

Javascript实时进行减法

Javascript实时进行减法,javascript,jquery,Javascript,Jquery,我正在做一个POS项目,我需要在手动添加客户提供的金额后,对小费进行实时减法。我不确定我的代码出了什么问题,所以请提供一些帮助 <div class="sidebar-category"> <div class="category-content" style="padding: 8px"> <div class="row"> <div class="col-sm-6">

我正在做一个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。好的,什么不起作用。它不起作用,它得不到提示,而且控制台中的总数就像“Uncaught SyntaxError:Unexpected number”我不认为是下行表决系统,它应该可以工作。请清楚地解释你想要完成什么,没有歧义,以及你希望最终结果是什么。这是什么{Session::get?看起来你在这里使用了一些库,所以只需标记它,让该字段中的其他人跳到这里。