关于setTimeout的最大延时上限
http://www.cnblogs.com/meteoric_cry/archive/2011/04/01/2002240.html
if (duration > 24*60*60*1000) { duration = 24*60*60*1000; }
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8" /> <title></title> </head> <body> <div id="box1">box1</div> <div id="box2">box2</div> <script> var timer; var i = 1; function auto() { timer = setInterval(function() { console.log(i); if (++i > 4) { i = 1; } }, 1000); } auto(); console.log(timer); // 1 不是setInterval(function... document.getElementById('box1').onclick = function() { clearInterval(timer); } document.getElementById('box2').onclick = function() { auto(); } </script> </body> </html>
setTimeout延时0毫秒的作用
http://www.cnblogs.com/xieex/archive/2008/07/11/1241137.html
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8" /> <title></title> </head> <body> <input id="t1" type="text" onkeydown="document.getElementById('t1text').innerHTML=this.value;" /> <span id="t1text"></span> <input id="t2" type="text" onkeydown="var t2=this;setTimeout(function(){document.getElementById('t2text').innerHTML=t2.value},0);" /> <span id="t2text"></span> <input id="makeinput" type="button" value="生成input" /> <span id="inpwrapper"></span> <input id="makeinput2" type="button" value="生成input" /> <span id="inpwrapper2"></span> <script> // 1 3 2 console.log(1); setTimeout(function() {console.log(2)}, 0); console.log(3); function get(id) { return document.getElementById(id); } get('makeinput').onmousedown = function() { var input = document.createElement('input'); input.setAttribute('type', 'text'); input.setAttribute('value', 'test1'); get('inpwrapper').appendChild(input); input.focus(); input.select(); }; get('makeinput2').onmousedown = function() { var input = document.createElement('input'); input.setAttribute('type', 'text'); input.setAttribute('value', 'test1'); get('inpwrapper2').appendChild(input); setTimeout(function(){ input.focus(); input.select(); }, 0); }; </script> </body> </html>