如何在预定义的时间后使用JavaScript停止Timer Tick? [英] How to stop Timer Tick Using JavaScript after a predefined time?

查看:94
本文介绍了如何在预定义的时间后使用JavaScript停止Timer Tick?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于网络的应用程序,即 LMS 学习管理系统。在这个应用程序中,学生可以阅读章节并对这些章节进行测试。并且为了阅读章节,特定时间被分配给使用计时器滴答捕获的用户。在每 12分钟之后阅读验证码(在aspx页面中开发)。现在我想当验证码出现在窗口上,同时阅读计时器应该暂停,并且当用户提交验证码计时器恢复时,它离开它的前一个刻度。为此,我尝试了使用JavaScript的解决方案,但它没有工作。我给出了一些代码参考,以便让人们了解。



代码为Captcha PopUp



< pre lang =xml> < script 类型 = text / javascript >
function showCaptchaOnChapter(){
ShowNewPage();
setTimeout('showCaptchaOnChapter()',720000);
}
< / script >





暂停计时器的代码



 <   script     type   =  text / javascript >  

var tmr = null;

函数getTimerReference(){
if(tmr == null)
tmr = $ find(<% = Timer1.ClientID %> );

返回tmr;
}

函数StopTimer(){
ReferenceTimer()._ stopTimer();
}

函数StartTimer(){
ReferenceTimer()._ startTimer();
}
< / script >





我打电话给 StopTimer()(在javascript中定义) )但功能不起作用。

所以请建议我还能做什么或者有没有办法用javascript做什么?

解决方案

find(<% = Timer1.ClientID %> );

返回tmr;
}

函数StopTimer(){
ReferenceTimer()._ stopTimer();
}

函数StartTimer(){
ReferenceTimer()._ startTimer();
}
< / script >





我打电话给 StopTimer()(在javascript中定义) )但功能不起作用。

所以请建议我还能做什么或者有没有办法用javascript做什么?


你可以用启动计时器的setInterval 。此调用将返回一个计时器对象,您可以使用它来停止它,使用 clearInterval

http://www.w3schools.com/jsref/met_win_setinterval.asp [ ^ ]。



你需要一些事件来称呼这个 clearInterval 功能。它应该在其他时间完成(我猜想,比你在 setInterval 中使用的间隔更长的间隔,你可以使用另一个计时器。因为你只需要一个事件明确,最好使用函数 setTimeout

http://www.w3schools.com/jsref/met_win_settimeout.asp [ ^ ]。



-SA


I am working on a web based application i.e LMS Learning Management System. In this application a student can read chapters and give test for that chapters. And for reading a chapter a specific time is alotted to the user which is capturing using the timer tick. While reading a captcha(developed in aspx page) coming at after every 12 minutes. Now i want when captcha comes on the window while reading the timer should get paused, and when user submit the captcha timer get resumed from where it left its previous tick. For this i have tried a solution using javascript but it didn't work. I am giving some code reference so you people get an idea.

Code for Captcha PopUp

<script type="text/javascript">
        function showCaptchaOnChapter() {
            ShowNewPage();
            setTimeout('showCaptchaOnChapter()', 720000);
        }
    </script>



Code for pause the timer

<script type="text/javascript">

        var tmr = null;

        function getTimerReference() {
            if (tmr == null)
                tmr = $find("<%= Timer1.ClientID %>");

            return tmr;
        }

        function StopTimer() {
            ReferenceTimer()._stopTimer();
        }

        function StartTimer() {
            ReferenceTimer()._startTimer();
        }
</script>



I had made a call of StopTimer() (defined in javascript) but the function didin't work.
So Please suggest me what else i could do or is there any way to do it using javascript ?

解决方案

find("<%= Timer1.ClientID %>"); return tmr; } function StopTimer() { ReferenceTimer()._stopTimer(); } function StartTimer() { ReferenceTimer()._startTimer(); } </script>



I had made a call of StopTimer() (defined in javascript) but the function didin't work.
So Please suggest me what else i could do or is there any way to do it using javascript ?


You can start timer using setInterval. This call will return it a timer object which you can use to stop it, using clearInterval:
http://www.w3schools.com/jsref/met_win_setinterval.asp[^].

You need some event to call this clearInterval function. It is should be done by some other time (I would presume, longer interval than the one you use in setInterval, you can use another timer. As you need just one event to clear, it's better to use the function setTimeout:
http://www.w3schools.com/jsref/met_win_settimeout.asp[^].

—SA


这篇关于如何在预定义的时间后使用JavaScript停止Timer Tick?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆