簡體   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