也许有人可以帮助我。
在我的游戏中您可以看到问题:
http://www.acsu.buffalo.edu/~jamesber/GameOne.html#
我制作了一个益智游戏,并包含一个重新启动游戏的 href 链接。它按照我想要的方式工作,除非你非常快地连续多次按下它,它会扰乱计时器并超快地刷新拼图。我想要的是在按钮上放置一个计时器,一旦按下按钮,2秒之内就无法按下。我试过这个:
var new; //global variable.
document.getElementById("restart").onclick=function(){
new = setTimeout(function() {
restartGame();
}, 2000);
clearTimeout(new); clearTimeout(timer); restartGame(); };
<b><a href="#" id="restart" style="position: absolute; left: 950px; top: 65px;">New Puzzle</a><b>
最佳答案
像这样使用 display:none 2 秒怎么样:
document.getElementById("restart").onclick=function(){
document.getElementById("restart").style.display = 'none';
new = setTimeout(function() {
restartGame();
}, 2000);
clearTimeout(new); clearTimeout(timer); restartGame(); };
然后,当在 2 秒 setTimeout 延迟后调用 restartGame() 时,使用 document.getElementById("restart").style.display = 'inline'; 使其重新出现
关于javascript - 禁用 href 链接一段时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23354537/