繁体   English   中英

为什么我会收到“... is not a function at HTMLButtonElement”错误?

[英]Why do I get "... is not a function at HTMLButtonElement" error?

我试图在事件侦听器中运行一个名为“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];
    }
}

我刚刚意识到我之前在我的 js 代码中将“重置”设置为另一个变量。 将较早的变量从“重置”重命名为其他变量解决了该问题。

菜鸟失误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM