【发布时间】:2016-06-07 02:02:11
【问题描述】:
目前是 JS 的新手,并创建了一个工资计算器,我有 4 个不同的条件可以满足,比如说 a1 a2 b1 b2,每个条件都有不同的工资率。 When the hourly pay rate is selected and the hours worked is input, it simply multiplies the hours worked by the pay rate, and leaves a thank you message in a text box at the bottom.我的问题是,函数不会在它应该的条件下停止,它会一直到最后一个 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
【问题讨论】:
-
输入是什么样的?
-
您是否年满 18 岁?
标签: javascript function return