目前新來的JS,並創建一個工資計算器,我有4個不同的條件可以滿足,可以說a1 a2 b1 b2,每個條件有不同的支付率。當選擇小時工資率並輸入工作時間時,只需將工作時間乘以工資率,並在底部的文本框中留下感謝信息。我的問題是,該函數並沒有停止在它應該的條件下,它直到最後一條if語句。說a2是滿足的條件,它會做這個條件,但它不會停止,並繼續到最後一條if語句。我已經嘗試在每個if語句的末尾添加一個返回碼,但是這會停止發佈謝謝郵件的完成功能。任何幫助表示感謝,謝謝。如何在滿足條件時完成功能?
var intName;
var intHours = 0,
intQualifyType, intAgeType;
var curWage = 0;
var blnContinue;
var strMessage = "";
var intNumCalc = 0;
var curTotal = 0;
function calcWage() {
intName = (document.getElementById('txtName').value);
intQualifyType = (document.getElementById('optQualifyType').value);
intAgeType = (document.getElementById('optAgeType').value);
intHours = parseInt(document.getElementById('txtHours').value);
if (intQualifyType == "Code1" || intAgeType == "Years2") {
curWage = intHours * 1;
}
alert(curWage);
if (intQualifyType == "Code1" || intAgeType == "Years1") {
curWage = intHours * 2;
}
document.getElementById('txtTotal').value = "$" + curWage.toFixed(2);
curWage = parseFloat(curWage);
intNumCalc++;
blnContinue = confirm("Do you have another quote to process");
if (blnContinue) {
clearall();
} else {
finishUp();
}
} //end of calwage
function clearall() {
document.getElementById('txtName').value = "";
document.getElementById('txtHours').value = "";
document.getElementById('msgInvest').value = "";
document.getElementById('txtTotal').value = "";
document.getElementById('txtName').focus();
} // end of clearall
function finishUp() {
strMessage = "Thank you for using our new Wage Calculator " + intName + "! ";
strMessage = strMessage + "For your hours this week you are currently owed $" + curWage.toFixed(2);
document.getElementById('msgFinish').value = strMessage;
intNumCalc = 0
curTotal = 0;
} //end of finishUp
輸入是什麼樣的? – epascarello
<選擇類型= 「文本」 ID = 「optQualifyType」> <選定= 「選擇了」 值= 「代碼1」 的選項>是 <選項值= 「代碼2」>否
是18歲或以上的你? <選擇類型= 「文本」 ID = 「optAgeType」> <選定= 「選擇了」 值= 「Years1」 選項>是 <選項值= 「Years2」>否
–