如何停止其中包含 addEventListener 的 forEach:Javascript

问题描述

我遇到了问题。在单击特定图像的大量时间后获得特定值时,我无法退出 addEventListener。

function game(role){    
    
    playRound(role,computerPlay());
    console.log(`Player: ${player_count} Computer: ${computer_count}`);
        
}



const buttons = document.querySelectorAll('button');

function pickRole(buttons){
    buttons.forEach((button) => {
        button.addEventListener('click',() => {
            if (button.className === "btn-1"){
                role = "rock";
            }else if (button.className === "btn-2"){
                role = "paper";
            }else if (button.className === "btn-3"){
                role = "scissors";
            }
            
            game(role);
            
        });
        
    });

}

pickRole(buttons);

我的程序正在检查 playRound() 函数中的每个语句,并且在获得 5 次胜利后,我希望它能够退出

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)