如果现金支付>总金额,如何保持总余额

$(function() {

    $("#payment").on("keydown keyup", sum);

 function sum() {


    const 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){

     


        let TotalBalance = balance;  

      TotalBalance = TotalBalance + (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 class="col-md-2">

        Previous 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>

大家好,我的问题是,如果现金支付 > 总金额,我希望总余额保持为 40。因为,支付的现金是患者支付的总金额。例如,如果客户的先前余额为 40,并且客户回来购买了一些东西,并且客户的总金额为 20,并且客户支付了 50,则余额仍为 40,因为 cashtenered > 总金额。因为在我的代码中,例如,总余额是 40,我在金额中输入 100,在现金中输入 500,总余额变为 90,我想保持 40。我搜索了这个问题,这个 tbalance id 中缺少的部分是 Parsefloat但我不知道如何应用这个



HUWWW
浏览 61回答 1
1回答

潇潇雨雨

$(function() {&nbsp; &nbsp; $("#payment").on("keydown keyup", sum);&nbsp;function sum() {var balance=Number.parseFloat(document.getElementById('balance').value);&nbsp; &nbsp; var payment = Number.parseFloat(document.getElementById('payment').value);&nbsp; &nbsp; var amount = Number.parseFloat(document.getElementById('amount').value);&nbsp; &nbsp;if (payment>=amount) {&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; document.getElementById('tbalance').value=balance;&nbsp; &nbsp;}&nbsp; &nbsp; else if(payment<amount){&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; TotalBalance = balance+ (amount - payment);&nbsp;&nbsp; &nbsp; &nbsp; document.getElementById('tbalance').value=TotalBalance;&nbsp; &nbsp; }&nbsp;}});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>&nbsp;<div class="col-md-2">&nbsp; &nbsp; &nbsp; &nbsp; Amount<input type="text" name="amount" id="amount" class="form-control" />&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <div class="col-md-2">&nbsp; &nbsp; &nbsp; &nbsp; Cash Tendered </strong>: <input type="text" name="payment" id="payment" class="form-control" />&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<div class="col-md-2">&nbsp; &nbsp; &nbsp; &nbsp; Balance</strong>: <input type="text" name="balance" id="balance"readonly="" class="form-control" value="40"/>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <div class="col-md-2">&nbsp; &nbsp; &nbsp; &nbsp;TOtalBalance</strong>: <input type="text" name="tbalance" id="tbalance"readonly="" class="form-control" value="40" />&nbsp; &nbsp; &nbsp; &nbsp; </div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5