[英]Why do I get "... is not a function at HTMLButtonElement" error?
I'm trying to run a function called "reset" in an event listener but I get the error "reset" is not a function at HTMLButtonElement.我试图在事件侦听器中运行一个名为“reset”的函数,但我收到错误“reset”不是 HTMLButtonElement 的函数。
for(var i = 0; i < gameMode.length; i++){
gameMode[i].addEventListener("click", function(){
for(var i = 0; i < gameMode.length; i++){
gameMode[i].classList.remove("selected");/*this line initially removes the class "selected" from all elements*/
this.classList.add("selected");/*it then adds it only to the element that was clicked*/
}
this.textContent === "Easy" ? numSquares = 3: numSquares = 6;
reset();
})
}
function reset(){
reset.innerHTML = "New Colors";
resultDisplay.innerHTML = "";
h1.style.backgroundColor = "steelblue";
colors = randomColorArr(numSquares);
pickedColor = pickColor();
//console.log("value of picedColor inside reset event listener: "+pickedColor);
colorDisplay.innerHTML = pickedColor;
for (var i = 0; i < squares.length; i++){
squares[i].style.backgroundColor = colors[i];
}
}
I just realised I had set "reset" earlier in my js code to another variable.我刚刚意识到我之前在我的 js 代码中将“重置”设置为另一个变量。 Renaming the earlier variable from " reset" to something else solved the issue.
将较早的变量从“重置”重命名为其他变量解决了该问题。
Rookie mistake.菜鸟失误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.