js setTimeout()的使用
生活随笔
收集整理的這篇文章主要介紹了
js setTimeout()的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、語法
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
轉載于:https://blog.51cto.com/studyofnet/1694030
總結
以上是生活随笔為你收集整理的js setTimeout()的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: _vsnprintf 用法
- 下一篇: iOS UI基础-6.0 UIActio