单击按钮时
/conf/server.xml
它在控制台中说" Uncaught ReferenceError:游戏未定义"。 我在脚本中将其定义为
System.out.println()
用
打电话给它<button onclick="game();">Submit</button>
它不应该运行吗?
答案 0 :(得分:2)
你的javascript中有一些错误。
javascript中没有 elseif 关键字。
其次,我们在支架订单方面存在一些问题。
这里有一个工作版本:
function game() {
var number = document.getElementById("myNumber").value;
var number = Number(number);
stepnumber.push(number);
var orignumber = number;
if (number !== "NaN") {
for (step = 0; step > 1; step + 0) {
if (number % 2 === 0) {
number = number / 2;
stepnumbers.push(number);
step += 1;
}
else if(number % 2 === 1) {
number = number * 3;
number += 1;
stepnumbers.push(number);
step += 1;
}
document.getElementById("output").innerHTML = "Your number, " + orignumber + " took " +
step + " steps to reach 1, the numbers it went through (in order) were: "
+ stepnumbers.toString() + ". Thanks for using this random 'tool'!";
}
}
else {
document.getElementById("output").innerHTML = "You didn't type in a number, try again."
};
}