如何停止计时器在预定义时间后使用JavaScript?

问题描述:

我正在开发基于Web的应用程序,例如LMS Learning Management System。在这个应用程序中,学生可以阅读章节并为该章节进行测试。并且为了阅读章节,将特定时间分配给用户capturing using the timer tick。在阅读本章时,captcha(即在aspx页面中开发)在每个12 minutes之后。现在,我希望在阅读时验证窗口中出现验证码,timer should get paused,以及用户提交验证码计时器时,从其离开之前的时间点获取resumed。为此,我尝试了使用JavaScript的解决方案,但没有奏效。如何停止计时器在预定义时间后使用JavaScript?

下面是我在这个剧本我已经设置验证码到达时间2分钟,所以我可以测试更快试图

<script type="text/javascript"> 


     function startTimer() { 
      var timer = $find("<%=Timer1.ClientID%>") 
      timer._startTimer(); 
     } 

     function stopTimer() { 
      var timer = $find("<%=Timer1.ClientID%>") 
      timer._stopTimer(); 
     } 

     function showCaptchaOnChapter() { 
      //stopTimer(); 
      ShowNewPage(); 

      setTimeout('showCaptchaOnChapter()', 120000); 
      stopTimer(); 
     } 
     function showRandomQuestionOnChapter() { 
      ShowChapterQuestion(); 
      setTimeout('showRandomQuestionOnChapter()', 900000); 
     } 
     //setTimeout('showCaptchaOnChapter()', 360000); 
     //setTimeout('showRandomQuestionOnChapter()', 120000); 
    </script> 

定义为ShowNewPage()

function ShowNewPage() { 
    var callbackFunctionArray = new Array(CloseCaptchaPopUp); 
    modalWin.ShowURL('Captcha.aspx', 225, 290, 'Please enter characters dislayed in image to proceed', null, callbackFunctionArray); 

} 

这里的中央器官捐赠名册。验证码在定期间隔即2分钟,但计时器不会停止。 我怎么能这样做?

超时发生后显示您的验证码并启动其他超时。

function showQuestion() { 
    updateTimer(); 
    getQuestion(); 
    setTimeout(showCaptcha, time); 
} 

function showCaptcha() { 
    getCaptcha(); 
    //some listener for submitting of captcha eg:submitCaptcha 
} 

function submitCaptcha() { 
    if captcha===correct 
     showQuestion(); 
} 
+0

showQuestion();功能不是必需的。我需要计时器在屏幕上显示验证码时暂停。 – 2014-10-29 08:13:16