使用jquery在keyup上减去值 [英] Substracting values on keyup using jquery
本文介绍了使用jquery在keyup上减去值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单中输入以下内容. total
(输入名称)和balance
(输入名称)的值相同.当任何用户在输入中输入paid_amount的值时,我想从总数中自动减去paid_amount的值,并将结果作为balance
的值输入到输入中.
能否请您向我展示如何使用jquery做到这一点.
谢谢
<input type="text" name="total" id="total" value="<?php echo $total;?>" />
<input type="text" name="paid_amount" id="paid_amount" value="" />
<input type="text" name="balance" id="balance" value="<?php echo $total;?>" />
解决方案
$('#paid_amount').on('keyup', function() {
if($.trim(this.value).length) {
var balance = parseFloat($('#total').val()).toFixed(2) -
parseFloat(this.value).toFixed(2);
$('#balance').val(balance);
}
});
I have the following inputs in my form. The value of total
(input name) and balance
(input name) are the same. When any user puts the value of paid_amount in the input, I want to automatically subtract the paid_amount value from the total and put the result as value of balance
in the input.
Could you please show me how to do this using jquery.
Thanks
<input type="text" name="total" id="total" value="<?php echo $total;?>" />
<input type="text" name="paid_amount" id="paid_amount" value="" />
<input type="text" name="balance" id="balance" value="<?php echo $total;?>" />
解决方案
$('#paid_amount').on('keyup', function() {
if($.trim(this.value).length) {
var balance = parseFloat($('#total').val()).toFixed(2) -
parseFloat(this.value).toFixed(2);
$('#balance').val(balance);
}
});
这篇关于使用jquery在keyup上减去值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文