禁用href链接一段时间

时间:2014-04-29 02:42:55

标签: javascript timer

也许有人可以帮助我。

我可以看到问题的游戏:

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>

1 个答案:

答案 0 :(得分:0)

如何使用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';

相关问题