clearetimeout功能不工作如何工作 [英] clearetimeout function not working how to make work

查看:73
本文介绍了clearetimeout功能不工作如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iam有两个settimeout函数,第一个将在window.load上执行,我想在第二个settimeout函数被调用时停止第一个计时器iam在按钮点击中调用第二个settimeout事件并且它必须按下另一个停止按钮后停止

first setoutout

iam having two settimeout functions first one will be executing on window.load and i want to stop the first timer when second settimeout function is called iam calling tha second settimeout event in button click and it has to stop after pressing another stop button
first settimeout

window.onload = testSp;
   function testSp() {
       alert("First");
       Timer1 = setTimeout("CheckStatus()", 4000);
   }







var secondsetimeout= function () {
       alert("s");
       clearTimeout(Timer1);
       Timer2 = setTimeout("CheckStatus()", 4000);
       }



并在跟随停止功能时停止秒针


and stoping secondtimer in following stop function

function stop() {
          clearTimeout(Timer2);
          Timer2 = 0;
}

推荐答案

试试这个



try this

<script type="text/javascript">
        var value = 'checkstatus';
        var CheckStatus = function ()
        { alert(value); }
        window.onload = testSp;
        var Timer1, Timer2;
        function testSp() {
            alert("First");
            value = 'first function'
            setInterval(CheckStatus, 4000);
        }
        var secondsetimeout = function () {
            alert("s");
            clearTimeout(Timer1);
            value = 'second function'
            Timer2 = setInterval(CheckStatus, 4000);
        }
        function stop() {
            setInterval(Timer2);
            Timer2 = 0;
        }


    </script>


这篇关于clearetimeout功能不工作如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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