0
我一直在努力這一段時間,它沒有考慮到信用卡債務餘額的輸入,並一直給我一個錯誤。jQuery沒有計算和顯示結果
此外,它不執行while函數來給我顯示結果。一雙新鮮的眼睛會有助於發現錯誤。
if (!isValid(currentBalance, 0, 10000)) {
return false
} else if (!isValid(interest, 0, 30)) {
return false
} else {
return true;
}
if (!isValid(mnth_pay, currentBalance*.02, currentBalance)) {
return false
} else {
var balance = $("#sliderOutput12").val(); // used in loop
var interest = $("#sliderOutput13").val()/100;
var mnth_pay = $("#sliderOutput14").val();
var currentBalance = balance.val();
var financeCharge = 0; // finance charge
var numberMonths = 0;
var totalInterest = 0;
}
while (currentBalance > 0) {
financeCharge = currentBalance*interest/12;
currentBalance = currentBalance - mnth_pay + financeCharge;
numberMonths++;
if (numberMonths > 300) {
alert("We are interrupting this process to prevent a hang which may result with a very high balance, high interest rate and low monthly payment.\n\nTry entering a higher monthly payment amount.")
mnth_pay.focus()
mnth_pay.select()
return
}
totalInterest += financeCharge;
}
所以移動函數以外的變量? – 2014-10-19 02:08:56
不需要,只需在使用它們之前定義它們即可。如果他們在外面,你仍然需要在函數內再次讀取它們以獲取當前值。在我的答案中查看最終版本。 – Shomz 2014-10-19 02:10:44
如果(參考isValid(mnth_pay,currentBalance * 0.02,currentBalance)!){ \t \t回假 }其他{ \t \t VAR餘額= $( 「#sliderOutput12」)VAL()。 \t \t //用於循環 \t var interest = $(「#sliderOutput13」)。val()/ 100; //(form.interest.value/100); \t var mnth_pay = $(「#sliderOutput14」)。val(); \t var currentBalance = balance.val(); \t var financeCharge = 0; \t \t \t //財務費用 \t var numberMonths = 0; \t var totalInterest = 0; } – 2014-10-19 02:13:29