Javascript 满足条件后如何重置时间

Javascript 满足条件后如何重置时间,javascript,jquery,html,jquery-ui,Javascript,Jquery,Html,Jquery Ui,我已经有一个开始按钮,但我需要的是重新启动按钮时,条件得到满足,使按钮再次点击 HTML代码: <div id="content" class="row-fluid"> <div class="span6 pull-right align-right white" style="max-width: 540px;"> <div style="display: block;"> 添加了“单击”变量,以检查时间是否需要重新启动 //-------

我已经有一个开始按钮,但我需要的是重新启动按钮时,条件得到满足,使按钮再次点击

HTML代码:

 <div id="content" class="row-fluid">
  <div class="span6 pull-right align-right white" style="max-width: 540px;">
    <div style="display: block;">

添加了“单击”变量,以检查时间是否需要重新启动

//---------------------------toggle-----------------------
$( ".picture" ).click(function() {
  $( "#container" ).toggle( "fold", 500 );

});
$( ".numbers1" ).click(function() {
  $( "#numbers" ).toggle();

});
//==========================================================

var done = true;
var clicked = true;
function check(counter){

         if (counter >= 0) {
           $("#count").text(counter);
         }
         if (counter === 0 && winner === 0) {
           $("<div title='Oh no!'><center><img src='https://www.foreignlanguagesforkids.com/playa/images/shark.png'></center><p style='text-align: center;'>Let's get Calamity Carl to the hospital, pronto! Lucky for Carl, the doctors are experts at fixing him up and he will be as good as new in no time, only to get himself in trouble all over again!</p><div style='margin-top: 15px; width: 100%;'><div style='float: left; width: 48%; text-align; center;'><a class='btn button' href='https://www.foreignlanguagesforkids.com/playa'>Play Again</a></div><div style='float: right; width: 48%; text-align: center;'><a class='btn button' href='https://www.foreignlanguagesforkids.com/playa'>End Game</a></div><div style='clear: both;'></div></div></div>").dialog();
           clearInterval(timer);
            $('#fail')[0].play();
            clicked = true;
         }

}
$("#startClock").click(function() {
var counter = 60;
 var winner = 0;
var winners=0;



//===============================================CAR DRAGGABLE===================

    $("#car").draggable({
    revert: "invalid", containment: "#wrapper",
    start: function(event, ui){
        if(!done) return false;
    },
    stop: function(event, ui){
        if($(".correct").length == $(".drop").length){
            setTimeout(function(){
                 $('#win').text(winner+' '+'stars'+' '+'earned');
            },500);
            winner = 1;
            clearInterval(timer);
            clicked = true;
        }
    }
    });

     $("#two").draggable({
    revert: "invalid", containment: "#wrapper",
    start: function(event, ui){
        if(!done) return false;
    },
    stop: function(event, ui){
        if($(".correct").length == $(".drop2").length){
            setTimeout(function(){
                  $('#win1').text(winners+' '+'stars'+' '+'earned');
            },500);
            winners = 2;

            clearInterval(timer);
            clicked = true;

        }
    }
    });

//===============================================/CAR DRAGGABLE     End===================

//====================================================================Two               draggable==========================

   if(counter > 59 && clicked){
   clicked = false;
    timer = setInterval(function(){
    check(counter);
    counter--;
    },1000);

}


//=========================================/TWO DRAGGABLE END==========================

});

//===================================================CAR DROPPABLE================================

$("#carDrop").droppable({
    accept: "#car",
    drop: function(event, ui) {
        if(ui.draggable.is("#car")){
            $(this).addClass("correct").find("p").html("correct!");
            done = false;
            ui.draggable.fadeOut(500);
            $(this).fadeOut(500,function(){
                done = true;
            });
        }
    }
});

//==================================================two droppable===========================

$("#twoDrop").droppable({
    accept: "#two",
    drop2: function(event, ui) {
        if(ui.draggable.is("#two")){
            $(this).addClass("correct").find("p").html("correct!");
            done = false;
            ui.draggable.fadeOut(500);
            $(this).fadeOut(500,function(){
                done = true;
            });
        }
    }
});
/------------------------------------切换-----------------------
$(“.picture”)。单击(函数(){
$(“#容器”)。切换(“折叠”,500);
});
$(“.numbers1”)。单击(函数(){
$(“#数字”).toggle();
});
//==========================================================
var done=true;
var=true;
功能检查(计数器){
如果(计数器>=0){
$(“#计数”)。文本(计数器);
}
如果(计数器===0&&winner==0){
$(“

让我们把灾难卡尔送到医院,马上!卡尔很幸运,医生们都是治疗他的专家,他很快就会恢复原状,只会让自己再次陷入困境。

”)。dialog(); 清除间隔(计时器); $('#fail')[0]。播放(); 单击=真; } } $(“#开始锁定”)。单击(函数(){ var计数器=60; var=0; var=0; //===========================================================================================可拖动的汽车=================== 美元(“#车”)。可拖动({ 回复:“无效”,包含:“包装器”, 开始:功能(事件、用户界面){ 如果(!done)返回false; }, 停止:功能(事件、用户界面){ 如果($(.correct”).length==$(.drop”).length){ setTimeout(函数(){ $(“#赢”).text(赢家+''+'stars'+'''+''''+'wind'); },500); 获胜者=1; 清除间隔(计时器); 单击=真; } } }); 美元(“#2”)。可拖动({ 回复:“无效”,包含:“包装器”, 开始:功能(事件、用户界面){ 如果(!done)返回false; }, 停止:功能(事件、用户界面){ 如果($(.correct”).length==$(.drop2”).length){ setTimeout(函数(){ $('#win1').text(winners+''+'stars'+'''+''''+'挣来的'); },500); 优胜者=2名; 清除间隔(计时器); 单击=真; } } }); //=========================================================================/汽车可牵引端=================== //==================================================================================================================================两个可拖动的========================== 如果(计数器>59&&单击){ 单击=假; 计时器=设置间隔(函数(){ 支票(柜台); 计数器--; },1000); } //=======================================================/两个可拖动端========================== }); //=====================================================================================================================可放下的汽车================================ $(“#carDrop”)。可拖放({ 接受:“汽车”, drop:函数(事件、用户界面){ if(ui.draggable.is(“#car”)){ $(this.addClass(“correct”).find(“p”).html(“correct!”); 完成=错误; 可拖动衰减(500); $(this).fadeOut(500,function(){ 完成=正确; }); } } }); //=================================================================================================两个可放下的=========================== $(“#twoDrop”)。可拖放({ 接受:“两个”, drop2:函数(事件、用户界面){ if(ui.draggable.is(“#two”)){ $(this.addClass(“correct”).find(“p”).html(“correct!”); 完成=错误; 可拖动衰减(500); $(this).fadeOut(500,function(){ 完成=正确; }); } } });
添加了“单击”变量,以检查时间是否需要重新启动

//---------------------------toggle-----------------------
$( ".picture" ).click(function() {
  $( "#container" ).toggle( "fold", 500 );

});
$( ".numbers1" ).click(function() {
  $( "#numbers" ).toggle();

});
//==========================================================

var done = true;
var clicked = true;
function check(counter){

         if (counter >= 0) {
           $("#count").text(counter);
         }
         if (counter === 0 && winner === 0) {
           $("<div title='Oh no!'><center><img src='https://www.foreignlanguagesforkids.com/playa/images/shark.png'></center><p style='text-align: center;'>Let's get Calamity Carl to the hospital, pronto! Lucky for Carl, the doctors are experts at fixing him up and he will be as good as new in no time, only to get himself in trouble all over again!</p><div style='margin-top: 15px; width: 100%;'><div style='float: left; width: 48%; text-align; center;'><a class='btn button' href='https://www.foreignlanguagesforkids.com/playa'>Play Again</a></div><div style='float: right; width: 48%; text-align: center;'><a class='btn button' href='https://www.foreignlanguagesforkids.com/playa'>End Game</a></div><div style='clear: both;'></div></div></div>").dialog();
           clearInterval(timer);
            $('#fail')[0].play();
            clicked = true;
         }

}
$("#startClock").click(function() {
var counter = 60;
 var winner = 0;
var winners=0;



//===============================================CAR DRAGGABLE===================

    $("#car").draggable({
    revert: "invalid", containment: "#wrapper",
    start: function(event, ui){
        if(!done) return false;
    },
    stop: function(event, ui){
        if($(".correct").length == $(".drop").length){
            setTimeout(function(){
                 $('#win').text(winner+' '+'stars'+' '+'earned');
            },500);
            winner = 1;
            clearInterval(timer);
            clicked = true;
        }
    }
    });

     $("#two").draggable({
    revert: "invalid", containment: "#wrapper",
    start: function(event, ui){
        if(!done) return false;
    },
    stop: function(event, ui){
        if($(".correct").length == $(".drop2").length){
            setTimeout(function(){
                  $('#win1').text(winners+' '+'stars'+' '+'earned');
            },500);
            winners = 2;

            clearInterval(timer);
            clicked = true;

        }
    }
    });

//===============================================/CAR DRAGGABLE     End===================

//====================================================================Two               draggable==========================

   if(counter > 59 && clicked){
   clicked = false;
    timer = setInterval(function(){
    check(counter);
    counter--;
    },1000);

}


//=========================================/TWO DRAGGABLE END==========================

});

//===================================================CAR DROPPABLE================================

$("#carDrop").droppable({
    accept: "#car",
    drop: function(event, ui) {
        if(ui.draggable.is("#car")){
            $(this).addClass("correct").find("p").html("correct!");
            done = false;
            ui.draggable.fadeOut(500);
            $(this).fadeOut(500,function(){
                done = true;
            });
        }
    }
});

//==================================================two droppable===========================

$("#twoDrop").droppable({
    accept: "#two",
    drop2: function(event, ui) {
        if(ui.draggable.is("#two")){
            $(this).addClass("correct").find("p").html("correct!");
            done = false;
            ui.draggable.fadeOut(500);
            $(this).fadeOut(500,function(){
                done = true;
            });
        }
    }
});
/------------------------------------切换-----------------------
$(“.picture”)。单击(函数(){
$(“#容器”)。切换(“折叠”,500);
});
$(“.numbers1”)。单击(函数(){
$(“#数字”).toggle();
});
//==========================================================
var done=true;
var=true;
功能检查(计数器){
如果(计数器>=0){
$(“#计数”)。文本(计数器);
}
如果(计数器===0&&winner==0){
$(“

让我们把灾难卡尔送到医院,马上!卡尔很幸运,医生们都是治疗他的专家,他很快就会恢复原状,只会让自己再次陷入困境。

”)。dialog(); 清除间隔(计时器); $('#fail')[0]。播放(); 单击=真; } } $(“#开始锁定”)。单击(函数(){ var计数器=60; var=0; var=0; //===========================================================================================可拖动的汽车=================== 美元(“#车”)。可拖动({ 回复:“无效”,包含:“包装器”, 开始:功能(事件、用户界面){ 如果(!done)返回false; }, 停止:功能(事件、用户界面){ 如果($(.correct”).length==$(.drop”).length){ setTimeout(函数(){ $(“#赢”).text(赢家+''+'stars'+'''+''''+'wind'); },500); 获胜者=1; 清除间隔(计时器); 单击=真; } } }); 美元(“#2”)。可拖动({ 回复:“无效”,包含:“包装器”, 开始:功能(事件、用户界面){ 如果(!done)返回false; }, 停止:功能(事件、用户界面){ 如果($(.correct”).length==$(.drop2”).length){ setTimeout(函数(){ $('#win1').text(winners+''+'stars'+'''+''''+'挣来的'); },500); 优胜者=2名; 清除间隔(计时器); 单击=真; } } }); //=========================================================================/汽车可牵引端=================== //==================================================================================================================================两个可拖动的========================== 如果(计数器>59&&单击){ 单击=假; 计时器=设置间隔(函数(){ 支票(柜台); 计数器--; },1000); } //=======================================================/两个可拖动端========================== });
// setup timer, keep pointer to it in mytimer variable

var mytimer = setTimeout(function(){
   alert('hello 2s have passed!');
},2000);

// cancel timer

clearTimeout(mytimer);