小编Nic*_*win的帖子

setTimeout似乎执行得太快

我一直在使用setTimeout和setInterval,我无法让代码按照我希望的方式执行.我的目标是创建一个setInterval,每隔三秒调用一次,并在十秒后清除它.但是,当我在firebug中运行代码时,我唯一得到的是一个数字,我假设它是setInterval的id,因为每次执行代码时,数字都会增加.

var intID = setInterval(function() {
    console.log("I've been called");},3000);


setTimeout(clearInterval(intID), 10000);
Run Code Online (Sandbox Code Playgroud)

javascript settimeout setinterval clearinterval

8
推荐指数
1
解决办法
6006
查看次数