clearTimeout()在jQuery中不起作用

时间:2018-07-23 05:51:47

标签: jquery settimeout cleartimeout

///下面给出的代码是我使用setTimeout()的循环功能

if(gameLevel==1){
        x=setTimeout(function(){gameEngine(radioValue,height,width,gameLevel)}, 3000);
    }else if(gameLevel==2){
        x=setTimeout(function(){gameEngine(radioValue,height,width,gameLevel)}, 2500);
    }
    else if(gameLevel==3){
        x=setTimeout(function(){gameEngine(radioValue,height,width,gameLevel)}, 2000);
    }
    else if(gameLevel==4){
        x=setTimeout(function(){gameEngine(radioValue,height,width,gameLevel)}, 1500);
    }
    else if(gameLevel==5){
        x=setTimeout(function(){gameEngine(radioValue,height,width,gameLevel)}, 1000);
    }

///我想在变量playerLife <1时停止此setTimeout(),我使用了如下所示的clearTimeout(),但是它不起作用,请帮忙,谢谢!!

if(playerLife<1)
    {
        console.log(playerLife);
      clearTimeout(x);


    }

0 个答案:

没有答案