小编Cha*_*ine的帖子

JS DOM:如何阻止点击事件触发?

我试图让按钮在满足特定条件时停止工作。由于某种原因,每当我得到 5 分时,无论哪一方,它都会继续前进,甚至不显示分数,我不知道为什么。我尝试过使用 while 循环,但它一直崩溃。有没有像 jQuery 那样简单地关闭它的方法?

const rock = document.querySelector('.rock');
const paper = document.querySelector('.paper');
const scissors = document.querySelector('.scissors');
const h3 = document.querySelector('h3');
const pscore = document.querySelector('#pscore');
const cscore = document.querySelector('#cscore');
let computerScore = 0;
let playerScore = 0;

function computerPlay() {
    var choice = Math.floor(Math.random() * 3 ) + 1; //generate a number 1-3 to find computer choice
    if(choice == 1) {
        return 'rock';
    }
    else if(choice == 2) {
        return 'paper';
    }
    else {
        return 'scissors'

    }
} …
Run Code Online (Sandbox Code Playgroud)

html javascript css dom

1
推荐指数
1
解决办法
1561
查看次数

标签 统计

css ×1

dom ×1

html ×1

javascript ×1