gpt4 book ai didi

javascript - 更改 jQuery 后存储最终值

转载 作者:数据小太阳 更新时间:2023-10-29 05:34:38 25 4
gpt4 key购买 nike

如何存储正在输入的余额的最终值?

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;
}
});

请帮我解决这个问题!

最佳答案

您可以添加另一个隐藏的输入字段以通过表单传递附加信息,或者将此信息存储到变量中并直接将其添加到 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>

关于javascript - 更改 jQuery 后存储最终值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53042483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com