如何存储输入的余额金额的最终值?
HTML
<div id="balance_amount">
balance amount:
<input type="number" id="balance-amount-input" name="balance_amount" value='+balance_amount+'>
</div>
JS
$('body').on('input','#balance-amount-input', function() {
$('.jconfirm #error-msg').hide();
var balance_amount_tmp=$(this).val();
$('#balance-amount-input').val(balance_amount_tmp);
if ((balance_amount_tmp-account_balance) > 0) {
$('.jconfirm #error-msg').show();
$('.jconfirm #error-msg').html('<p class="alert alert-warning">not enough</p>');
$('.jconfirm-buttons button.btn-success').attr('disabled', 'true');
return;
} else {
offline_amount = (total_amount - balance_amount_tmp).toFixed(2);
$('#offline_amount').html(offline_amount);
$('.jconfirm-buttons button.btn-success').removeAttr('disabled');
return;
}
});
请帮助我解决这个问题!
答案 0 :(得分:1)
您可以添加另一个隐藏的输入字段,以通过表单传递其他信息,或者将该信息存储到变量中并将其直接添加到ajax调用中。例如,您可以使用以下代码:
$('body').on('input','#balance-amount-input', function() {
$('.jconfirm #error-msg').hide();
var balance_amount_tmp=$(this).val();
// $('#balance-amount-input').val(balance_amount_tmp); //PTK: you don't need this line
if ((balance_amount_tmp-account_balance) > 0) {
$('.jconfirm #error-msg').show();
$('.jconfirm #error-msg').html('<p class="alert alert-warning">用户余额不足</p>');
$('.jconfirm-buttons button.btn-success').attr('disabled', 'true');
return;
} else {
offline_amount = (total_amount - balance_amount_tmp).toFixed(2);
$('#offline_amount').val(offline_amount); //PTK: I changed here html to val
$('.jconfirm-buttons button.btn-success').removeAttr('disabled');
return;
}
});
<div id="balance_amount">
balance amount:
<input type="number" id="balance-amount-input" name="balance_amount" value='+balance_amount+'>
<input type="hidden" id="offline_amount" name="offline_amount" value="">
</div>