我有一个td:
<td class="floatingTermsVehicle totalNetVehicle bold">$28,435</td>
即显示两个输入的总和:
<label for="estimatedTaxesAndFees" class="form-control-label etfl">Estimated Taxes and Fees</label>
<input type="number" class="form-control" id="estimatedTaxesAndFees" placeholder="$0" onkeypress="return isNumberKey(event)" onBlur="addCommas(this)"/>
基于此:
$(document).ready(function () {
$(function () {
$("body").on("blur", "#vehiclePrice,#estimatedTaxesAndFees", function () {
updateTotalNetVehicle();
});
var updateTotalNetVehicle = function () {
var input1 = parseInt($('#vehiclePrice').val()) || 0;
var input2 = parseInt($('#estimatedTaxesAndFees').val()) || 0;
var sum = input1 + input2;
$('.totalNetVehicle').text('$' + sum.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
};
});
});
我怎样才能得到td中显示的数值,该值根据上面的等式变化,然后填充totalNetVehicle类?
答案 0 :(得分:0)
尝试
var text = $.trim($('.totalNetVehicle').text());
var value = +text.substring(1) || 0
答案 1 :(得分:0)
只需在外面声明您的sum
变量:
var sum,
updateTotalNetVehicle = function () {
var input1 = parseInt($('#vehiclePrice').val()) || 0,
input2 = parseInt($('#estimatedTaxesAndFees').val()) || 0;
sum = input1 + input2;
$('.totalNetVehicle')
.text('$' + sum.toFixed(2)
.replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
};
然后你只需要使用sum
。
答案 2 :(得分:0)