关于setTimeout的问题。 setTimeout (function(){ alert("A");},0);alert("b"); 这个代码为什么是先出来B,再出来A呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你是不是认为setTimeout设置为0,应该是即时执行啊?其实不然。 If the currently running task is a task that was created by the setTimeout() method, and timeout is less than 4, then increase timeout to 4. 做个顺水人情吧,翻译一下:setTimeout 定时运行的方法最短时间为 4 毫秒 其实和4毫秒没关系测试下面代码alert("A");setTimeout (function(){ alert("B");},0);alert("C");无论在弹出A框等待多久时间,都会弹出C先。。这和js的单线程原理有关系 不用谈深了,否则就说不完了,你懂的参考 http://ejohn.org/blog/how-javascript-timers-work/ 呵呵。其实我不想太多人误会了setTimeout setTimeout (function(){ alert("A");},0);alert("b"); 难道会先弹出b,然后等待四毫秒,然后再弹出a? 是4毫秒后把任务放到线程队列中,然后等待前面的任务完成后立刻执行setTimeout (function(){ alert("A");},3000);alert("b"); 如果alert你等待超过3000毫秒后点确定,alert("A")会立刻执行 http://blog.csdn.net/legend1988/article/details/6971588 如何实现WEB直接打印? JavaScript The Definitive Guide 6th Edition javascript 继承, 出现溢出, 求解 jQuery 插件 chili的用法?? js统计数据问题? 一个text的onChange事件,可否连续执行两个函数? 如何使表單自動提交?? 求助!!如何写脚本实现自动点击按钮 求助Js解密,本人第一次遇见这种加密【$$=~[];$$={___:开头的】。 firefox浏览器的组件问题 js无法控制后添加的对像(急) 求一个正则
测试下面代码
alert("A");
setTimeout (function(){ alert("B");},0);
alert("C");无论在弹出A框等待多久时间,都会弹出C先。。这和js的单线程原理有关系
参考 http://ejohn.org/blog/how-javascript-timers-work/
呵呵。其实我不想太多人误会了setTimeout
难道会先弹出b,然后等待四毫秒,然后再弹出a?