Ale*_*yuv 3 javascript settimeout
简单的例子:
for (var i = 0; i < 10; ++i) {
console.log(i); // <--- should be show with delay in 300ms
}
Run Code Online (Sandbox Code Playgroud)
简单的setTimeout使用当然不起作用......我猜应该使用闭包..
编写递归函数很简单:
function display(i)
{
if (i == 10) return;
setTimeout(function(){ console.log(i); display(i+1); }, 300);
}
Run Code Online (Sandbox Code Playgroud)