js setTimeout()的使用
生活随笔
收集整理的這篇文章主要介紹了
js setTimeout()的使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、語法
setTimeout(code,millisec)
code:是含有 JavaScript 語句的字符串。這個語句可能諸如 "alert('5 seconds!')",或者對函數(shù)的調(diào)用,諸如 alertMsg()。
millisec:指示從當前起多少毫秒后執(zhí)行第一個參數(shù)。
?
?
?
二、setTimeout(code,millisec)中code包含形參的用法
?
?
例如
?
var?msg='dfdsf';setTimeout(alert(msg),1000); //alert(msg)會被立即執(zhí)行
setTimeout(“alert(msg)”,1000);//系統(tǒng)報錯
解決辦法是使用匿名函數(shù)回調(diào)
?
var msg='fewweeeee';
?
setTimeout(function(){alert(msg);},1000);
參考資料:js setTimeout??? http://www.studyofnet.com/news/916.html
轉(zhuǎn)載于:https://blog.51cto.com/studyofnet/1694030
總結(jié)
以上是生活随笔為你收集整理的js setTimeout()的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: _vsnprintf 用法
- 下一篇: iOS UI基础-6.0 UIActio