简体   繁体   English

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

[英]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.

相关问题 为什么我会使用此事件侦听器代码获得 object HTMLButtonElement? - Why do I get object HTMLButtonElement with this event listener code? 显示不是HTMLButtonElement错误时的功能 - Show Is Not A Function At HTMLButtonElement Error 为什么我在 HTMLButtonElement 的赋值中得到 Uncaught SyntaxError: Invalid left-hand side。? - Why do I get Uncaught SyntaxError: Invalid left-hand side in assignment at HTMLButtonElement.? 为什么会出现“不是函数”错误? - Why do I get “is not a function” error? 为什么我在返回函数中收到此错误? - Why do I get this error in the return function? 为什么会出现错误:“ .isValid()”不是一个函数? - Why do I get the error: “.isValid()” is not a function? 反应错误:(功能)未在HTMLButtonElement.onclick上定义 - React Error : (function) is not defined at HTMLButtonElement.onclick 错误出现为“Uncaught TypeError: notesObj.push is not a function at HTMLButtonElement。<anonymous> “。请任何人建议做什么</anonymous> - Error comes as "Uncaught TypeError: notesObj.push is not a function at HTMLButtonElement.<anonymous>" . Please anyone suggest what to do 未捕获的类型错误:{function} 不是 HTMLButtonElement.onclick 处的 function。 我该如何解决这个错误? - Uncaught TypeError: {function} is not a function at HTMLButtonElement.onclick. How can I fix this error? 为什么我得到 Uncaught ReferenceError: Delete is not defined at HTMLButtonElement.onclick 如果已经定义? - Why I get Uncaught ReferenceError: Delete is not defined at HTMLButtonElement.onclick IF IS already defined?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM