stop settimeout in recursive function

后端 未结 7 2131
旧时难觅i
旧时难觅i 2020-12-01 11:24

my problem is that I can not stop a timer.

I had this method to set a timeout from this forum. It supposed to store the identifyer in the global variable. By accid

7条回答
  •  情书的邮戳
    2020-12-01 11:55

    I think you misunderstand 'setTimeout' and 'clearTimeout'.

    If you want to set a timer that you want to cancel later, do something like:

    foo = setTimeout(function, time);
    

    then call

    clearTimeout(foo);
    

    if you want to cancel that timer.

    Hope this helps!

提交回复
热议问题