最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - alert msg once, 5 seconds after the page loaded - Stack Overflow

programmeradmin3浏览0评论

I want to do the below with pure JavaScript if it is possible (or jQuery)

  1. the page is fully loaded.
  2. wait 5 seconds.
  3. alert('msg') once with no setInterval loops.

I want to do the below with pure JavaScript if it is possible (or jQuery)

  1. the page is fully loaded.
  2. wait 5 seconds.
  3. alert('msg') once with no setInterval loops.
Share Improve this question edited Apr 26, 2015 at 14:54 elixenide 44.9k16 gold badges78 silver badges102 bronze badges asked Apr 26, 2015 at 14:20 Egy SuccessEgy Success 1121 gold badge1 silver badge8 bronze badges 1
  • 2 The downvotes are a result of lack of research effort as this shouldn't be hard to research yourself and at least e up with a code attempt – charlietfl Commented Apr 26, 2015 at 14:52
Add a ment  | 

3 Answers 3

Reset to default 3

Try setTimeout:

document.onload = setTimeout(function () { alert('msg'); }, 5000);

jQuery solution:

$(document).ready(function()
{
    setTimeout(function()
    {
        alert('msg');
    }, 
    5000);
});
<script src="https://ajax.googleapis./ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Use setTimeout, not setInterval. I kept the answer as verbose as the question.

Try this:

$(document).ready(function(){
    setTimeout(function(){ alert("msg");}, 5000)
})

do not forget put jquery reference to your html header:

<script src="http://code.jquery./jquery-2.1.3.min.js"></script>
发布评论

评论列表(0)

  1. 暂无评论