一、语法


setTimeout(code,millisec)


code:是含有 JavaScript 语句的字符串。这个语句可能诸如 "alert('5 seconds!')",或者对函数的调用,诸如 alertMsg()。


millisec:指示从当前起多少毫秒后执行第一个参数。

 

 

 

二、setTimeout(code,millisec)中code包含形参的用法

 

 

例如

 

var msg='dfdsf';
 

setTimeout(alert(msg),1000); //alert(msg)会被立即执行


setTimeout(“alert(msg)”,1000);//系统报错


解决办法是使用匿名函数回调

 

var msg='fewweeeee';
 
setTimeout(function(){alert(msg);},1000);




参考资料:js setTimeout    http://www.studyofnet.com/news/916.html