我使用以下函数从输入中获取值并从固定值中扣除金额。当用户单击屏幕上的数字键盘时会发生这种情况。
function totalFocusOut(elem){
var subTotal = $(elem).parent().parent().find('.total-due').val();
var paidAmount = $(elem).val();
var balanceAmount = parseFloat(subTotal) - parseFloat(paidAmount);
$('.final-value').html(balanceAmount.toFixed(2));
}
该功能由以下功能触发
$('.amount').blur(function(){
if($(this).val() != ""){
totalFocusOut($(this));
}
});
调用该函数时,它不会减少用户输入的第一个值!bt 在输入第二个值时开始减少第一个值!
例如,用户首先单击数字 6 按钮。然后数字 7 按钮。从理论上讲,该函数应首先从数量中减少 6,然后从数量中减少 67。金额是固定的,我将更新后的金额保存在另一个变量中。如何使函数先减少第一个值,然后再减少第二个值。
谢谢你。
这是 HTML 代码
<div id="settle-cash">
<div id="settlement-cash">
<div id="input-div">
<label for="table-number">Table No</label>
<input class="table-number" placeholder="Table Number" type="text"></text>
</div>
<div id="input-div">
<label for="room">Room No</label>
<input class="room" placeholder="Room Number" type="text"></text>
</div>
<div id="input-div">
<label for="room">No of Guests</label>
<input class="num-of-guests" placeholder="Number of Guests" type="text"></text>
</div>
<div id="input-div">
<label for="total"">Total</label>
<input class="total" placeholder="Total" type="text"></text>
</div>
<span style="padding-left: 16px">Discount Type:</span>
<input type="radio" id="dis-percentage" name="discount-type" checked="checked" value="percentage">Percentage</input>
<input type="radio" id="dis-amount" name="discount-type" value="amount">Amount</input>
<div id="input-div">
<label for="discount">Discount</label>
<input class="discount" placeholder="00.00" type="text"></text>
</div>
<div id="input-div">
<label for="total-due">Total Due</label>
<input class="total-due" placeholder="Total Due" value="Total Due" type="text"></text>
</div>
<div class="balance-section">
<span class="balance">Balance</span>
<span class="final-value"></span>
</div>
</div>
<div id="amount">
<input class="amount" placeholder="Enter Amount" type="text"></text>
<!-- Onscreen Number Pad -->
<div id="number-pad">
<div class="metal linear num-button">
<span>1</span>
</div>
<div class="metal linear num-button">
<span>2</span>
</div>
<div class="metal linear num-button">
<span>3</span>
</div>
<div class="metal linear num-button">
<span>4</span>
</div>
<div class="metal linear num-button">
<span>5</span>
</div>
<div class="metal linear num-button">
<span>6</span>
</div>
<div class="metal linear num-button">
<span>7</span>
</div>
<div class="metal linear num-button">
<span>8</span>
</div>
<div class="metal linear num-button">
<span>9</span>
</div>
<div class="metal linear num-button">
<span>0</span>
</div>
<div class="button del metal linear">
<span>Del</span>
</div>
<div class="button settle metal linear">
<span>SETTLE</span>
</div>
<div class="clear"></div>
</div>
</div>
</div>