有一个函数,我想显示在div中的总数,它不工作。有任何想法吗?模糊显示在字段总数
基本上,在blur模式下,将vehiclePrice中的输入值乘以10%(0.010),然后在estimatedTaxesAndFees字段中将该总数显示为两个十进制固定量。
HTML:
<label for="vehiclePrice" class="form-control-label vpl">Vehicle Price</label>
<input type="number" class="form-control" id="vehiclePrice" placeholder="$0" onkeypress="return isNumberKey(event)" onBlur="addCommas(this)" value="28435" />
<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)"/>
JS:
$(document).ready(function() {
$(function() {
$("body").on("blur", "#vehiclePrice", function() {
updateTotalNetVehicle();
});
var updateTotalNetVehicle = function() {
var input1 = parseInt($('#vehiclePrice').val()) || 0;
var number1 = 0.10;
var sum = input1 * number1;
$('#estimatedTaxesAndFees').text('$' + sum.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
};
});
});
'未捕获的ReferenceError:addCommas未定义' –
这是为了别的...我的坏。更新小提琴:http://jsfiddle.net/icweat/4aufj/3/ –