我正在用jQuery构建西蒙颜色游戏,我试图在游戏关闭或玩家点击错误颜色时禁用点击事件。我在网上读到了关于. prop("disalbe",真)和about. attr("disabled","disabled")的信息,但它们对我都不起作用。我使用的是div而不是button元素
<div class="container" id="container">
<div class="row">
<div type="button" id="green" class="btn green">
</div>
<div type="button" id="red" class="btn red">
</div>
</div>
<div class="row">
<div type="button" id="yellow" class="btn yellow">
</div>
<div type="button" id="blue" class="btn blue">
</div>
</div>
</div>
allButtons.click(function() { // CLICK EVENT LISTENER
const userChosenColour = this.id;
userClickedPattern.push(userChosenColour);
const userButton = $(`#${this.id}`);
userButton.fadeTo(100, 0.1, function() { $(this).fadeTo(500, 1.0); });
makeSound(this.id)
if (checkAnswer(userClickedPattern.length)) { // CONDITIONS TO CHECK THE CURRENT CLICK
if (userClickedPattern.length === gamePattern.length) {
title.text('Success')
setTimeout(function() {nextSequence()}, 1000);
}
return true;
} else {
// allButtons.attr('disabled',true);
title.text('Wrong');
makeSound('wrong');
flashBackground();
allButtons.prop('disabled', true);
setTimeout(function() {resetGame()}, 500);
return false;
}
});
rn的结果是什么都没有发生。谢谢你的帮助!
1条答案
按热度按时间pvcm50d11#
您可以将CSS属性
pointer-events
设置为none
以防止单击。