admin管理员组文章数量:1287809
My
setInterval('name(var)',6000);
won't clear with:
clearInterval('name(var)');
or with:
clearInterval('name(var)');
why?
My
setInterval('name(var)',6000);
won't clear with:
clearInterval('name(var)');
or with:
clearInterval('name(var)');
why?
Share Improve this question edited Jul 9, 2020 at 10:16 braX 11.8k5 gold badges22 silver badges37 bronze badges asked Feb 24, 2011 at 21:50 Toni Michel CaubetToni Michel Caubet 20.2k58 gold badges217 silver badges387 bronze badges 2- 1 Pass functions to setInterval, not strings to be evaled. Passing a string is ugly and inefficient at best and does horrible things to scope at worst. – Quentin Commented Feb 24, 2011 at 21:53
- i was getting name setInterval error (on firebu) if not..) can you please write the correct syntax for it? – Toni Michel Caubet Commented Feb 24, 2011 at 21:57
4 Answers
Reset to default 5setInterval
returns a handle of the interval, so you do it like this:
var myInterval = setInterval(function(){ name(var) }, 6000);
clearInterval(myInterval);
Note: Notice how I used a anonymous function instead of a string too.
You need to store the returned intervalID and pass it to clearInterval later.
var intervalID = setInterval('name(var)',6000);
clearInterval(intervalID);
You need to pass in the interval id returned from setInterval ex:
var id = setInterval('name(var)', 2000);
clearInterval(id);
More information here. http://www.elated./articles/javascript-timers-with-settimeout-and-setinterval/
This will work:
var id = setInterval('name(var)',6000);
clearInterval(id);
本文标签: setintervalSimple question about how to clearInterval() in JavascriptStack Overflow
版权声明:本文标题:setinterval - Simple? question about how to clearInterval() in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741324622a2372403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论