我使用" rate" "量" "个月"和#34;付款。"
当用户点击计算时,它应该拉出" rate" "量"和"月"并计算付款。开头的值是:
$('#loanAmount').val("$" + loanAmount);
$('#apr').val(apr - 1.6 + "%");
$('#months').val(months);
我试图删除任何非数字字符并进行数学计算,但它们都在返回" NaN"在我下面的第一个提醒中,我已经尝试了一切。
$('#submit').on('click', function () {
var rawLoanAmount1 = ($('#loanAmount').val());
var rawApr1 = ($('#apr').val());
var rawMonths1 = ($('#months').val());
var rawLoanAmount2 = rawLoanAmount1.replace(/\D/g,'');
var rawApr2 = rawApr1.replace(/\D/g,'');
var rawMonths2 = rawMonths1.replace(/\D/g,'');
var loanAmount = parseInt($(rawLoanAmount2).val());
var apr = parseFloat($(rawApr2).val());
var months = parseInt($(rawMonths2).val());
alert("apr =" + apr + " loanAmount =" + loanAmount + " months =" + months);
var newApr = apr / 1200;
var firstStep = 1 + newApr;
var secondStep = Math.pow(firstStep, months);
var thirdStep = newApr * secondStep;
var top = thirdStep;
var firstStepB = 1 + newApr;
var secondStepB = Math.pow(firstStepB, months);
var thirdStepB = secondStepB - 1;
var bottom = thirdStepB;
var firstStepComp = top / bottom;
var secondStepComp = loanAmount * firstStepComp;
var compAnswer = secondStepComp;
var compAnswerRounded = Math.round(compAnswer);
var tal = parseInt($(compAnswerRounded).val());
$('#payment').val(tal);
return false;
})