我正在为购房者构建一个计算器。每次用户在字段中输入数字时,最终购买价格都会更新。有几个字段实际上占总购买价格的 6 倍。我希望 6 个月的计算仅在输入该特定字段后显示。
目前 t 有效,但不能计算正确的数量。但是,如果您返回文本字段并输出文本,他的计算器可以正常工作。最终购买价格每次都正确计算。
http://coyle.webedgemedia.com/Admin/BidSheet/47
http://jsfiddle.net/webedge/7fyV5/(CSS 没有正确通过,但您可以了解正在发生的事情)
我确信它与 DOM 有关,当我从它中取出时不知道该值,但我认为 .on() 函数会帮助解决这个问题。任何帮助表示赞赏。
$('.currency').on("blur", function () {
var purchasePrice = 0;
var futureSalesPrice = $('#txtFutureSales').length > 0 ? $('#txtFutureSales').val().replace("$", "").replace(",", "") : 0;
var purchaseLoan = $('#txtPurchaseLoan').length > 0 ? $('#txtPurchaseLoan').val().replace("$", "").replace(",", "") : 0;
var remodeling = $('#txtRemodeling').length > 0 ? $('#txtRemodeling').val().replace("$", "").replace(",", "") : 0;
var utilities = $('#txtUtilities').length > 0 ? $('#txtUtilities').val().replace("$", "").replace(",", "") : 0;
var HOADues = $('#txtHOADues').length > 0 ? $('#txtHOADues').val().replace("$", "").replace(",", "") : 0;
var Insurance = $('#txtInsurance').length > 0 ? $('#txtInsurance').val().replace("$", "").replace(",", "") : 0;
var Taxes = $('#txtTaxes').length > 0 ? $('#txtTaxes').val().replace("$", "").replace(",", "") : 0;
var LoanInterestCarry = ('#txtLoanInterestCarry').length > 0 ? $('#txtLoanInterestCarry').val().replace("$", "").replace(",", "") : 0;
var Inspection = $('#txtInspection').length > 0 ? $('#txtInspection').val().replace("$", "").replace(",", "") : 0;
var SaleTitle = $('#txtSaleTitle').length > 0 ? $('#txtSaleTitle').val().replace("$", "").replace(",", "") : 0;
var RealEstateSales = $('#txtRealEstateSales').length > 0 ? $('#txtRealEstateSales').val().replace("$", "").replace(",", "") : 0;
var ProjectedProfit = $('#txtProjectedProfit').length > 0 ? $('#txtProjectedProfit').val().replace("$", "").replace(",", "") : 0;
utilities = utilities * 6;
HOADues = HOADues * 6;
Insurance = Insurance * 6;
Taxes = Taxes * 6;
LoanInterestCarry = LoanInterestCarry * 6;
$('.currency').formatCurrency();
purchasePrice = futureSalesPrice - purchaseLoan - remodeling - Insurance - utilities - HOADues - Taxes - LoanInterestCarry - Inspection - SaleTitle - RealEstateSales - ProjectedProfit;
$('#txtUtilities').on("blur", function () {
$('.utilitiesMonthly').text(utilities).formatCurrency();
});
$('#txtHOADues').on("blur", function () {
$('.hoaMonthly').text(HOADues).formatCurrency();
});
$('#txtInsurance').on("blur", function () {
$('.insuranceMonthly').text(Insurance).formatCurrency();
});
$('#txtTaxes').on("blur", function () {
$('.taxesMonthly').text(Taxes).formatCurrency();
});
$('#txtLoanInterestCarry').on("blur", function () {
$('.loanInterestCarry').text(LoanInterestCarry).formatCurrency();
});
$('.price').text(purchasePrice).formatCurrency();
});