我需要将var result1,result2,result3传递给三个单独的文本区域。 我的代码不允许我这样做。有人可以帮忙吗?谢谢。
var overtimeRate = 1.5;
var regularHours = prompt("How many regular hours?");
var overtime = prompt("How many overtime hours?");
var pay = regularHours * hourRate;
var overtimePay = overtime * overtimeRatePerHour;
var hourRate = prompt("What is the hour rate of pay?");
var overtimeRatePerHour = hourRate * overtimeRate;
function calculator() {
var result = pay;
document.getElementById("textarea1").value = result;
var result1 = overTimePay;
document.getElementById("textarea2").value = result1;
var result2 = overTimePay + pay;
document.getElementById("textarea3").value = result2;
}
html:
<body>
<button onclick="calculator()">Calculate</button>
<button onclick="reset1()" id="reset">Reset</button>
<textarea id="textarea1" readonly=""></textarea>
<textarea id="textarea2" readonly=""></textarea>
<textarea id="textarea3" readonly=""></textarea>
</body>
答案 0 :(得分:1)
试试这个。如果错误,你调用变量的顺序。始终检查控制台中的错误 。加速率的拼写也是错误的
var overtimeRate = 1.5;
var regularHours = prompt("How many regular hours?");
var overtime = prompt("How many overtime hours?");
var hourRate = prompt("What is the hour rate of pay?");
var pay = regularHours * hourRate;
var overtimeRatePerHour = hourRate * overtimeRate;
var overtimePay = overtime * overtimeRatePerHour;
function calculator() {
var result = pay;
document.getElementById("textarea1").value = result;
var result1 = overtimeRate;
document.getElementById("textarea2").value = result1;
var result2 = overtimeRate+ pay;
document.getElementById("textarea3").value = result2;
}