Stop setInterval call in JavaScript

前端 未结 16 2196
星月不相逢
星月不相逢 2020-11-21 05:00

I am using setInterval(fname, 10000); to call a function every 10 seconds in JavaScript. Is it possible to stop calling it on some event?

I want the us

16条回答
  •  感情败类
    2020-11-21 05:58

    @cnu,

    You can stop interval, when try run code before look ur console browser (F12) ... try comment clearInterval(trigger) is look again a console, not beautifier? :P

    Check example a source:

    var trigger = setInterval(function() { 
      if (document.getElementById('sandroalvares') != null) {
        document.write('
    SandroAlvares
    '); clearInterval(trigger); console.log('Success'); } else { console.log('Trigger!!'); } }, 1000);
    Author

提交回复
热议问题