【发布时间】:2018-04-27 17:06:59
【问题描述】:
我需要打印从 Gross 输入框(第 3 个框)内的选项获得的计算,但我收到的是 NaN,而不是计算。
答案应根据以下函数返回总工资计算。
如果工作小时数小于等于 40,则计算将在 if 条件内进行,否则,将进行不同的计算。
function myFunction() {
var hoursWorked;
var hourlyRate;
document.getElementById("hours").value = hoursWorked;
document.getElementById("payrate").value = hourlyRate;
if (hoursWorked <= 40) {
var grossPay = parseInt((hoursWorked * hourlyRate)).toFixed(2);
document.getElementById("gross").value = grossPay;
} else {
var grossPay = parseInt((40 * hourlyRate + 1.5 * hourlyRate * (hoursWorked - 40))).toFixed(2);
document.getElementById("gross").value = grossPay;
}
}
# Add A H1 Heading Of "Gross Pay Calculation"
<form>
Hourly Rate:
<select id="payrate" align="right">
<script>
for(var d=10;d<=60;d++) {
document.write("<option>"+(d)+"</option>");
d+=9;
document.getElementById("payrate").value;
}
</script>
</select><br> Hours Worked:
<select id="hours" align="right">
<script>
for(var d=10;d<=60;d++) {
document.write("<option>"+d+"</option>");
d+=4;
document.getElementById("hours").value;
}
</script>
</select><br>
</form>
Gross Pay: <input type="text" id="gross" align="right"><br><br>
<input type="submit" value="GrossPay" onclick="myFunction()">
【问题讨论】:
-
document.getElementById("hours").value = hoursWorked; document.getElementById("payrate").value = hourlyRate;你认为这是在做什么? -
和提交按钮提交。
标签: javascript html nan