javascript – 如何在我的脚本中加入时间延迟?

前端之家收集整理的这篇文章主要介绍了javascript – 如何在我的脚本中加入时间延迟?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我的剧本中延迟3秒钟

但是我怎么能这样做,我不知道!

我的剧本:

<script type="text/javascript">

    var baslik = document.title;
    $(document).ready(function () {

        document.title = '(Welcome)' + baslik; // After 3 seconds 
        document.title = '(What can i do for you ?)' + baslik; // After 3 seconds
        document.title = '(Thank u for viewing to me)' + baslik; // After 3 seconds 
        document.title = baslik;
    });         
</script>

解决方法

使用超时 http://www.w3schools.com/jsref/met_win_settimeout.asp
var baslik = document.title;
postMsg = function(txt) {
   document.title = txt + baslik;
}

$(document).ready(function(){
  setTimeout("postMsg('(Welcome)')",3000);
  setTimeout("postMsg('(What can i do for you ?)')",6000);
  setTimeout("postMsg('(Thank u for viewing to me)')",9000);
});
原文链接:https://www.f2er.com/js/159523.html

猜你在找的JavaScript相关文章