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

javascript - How to show a label message, then hide it after some seconds? - Stack Overflow

programmeradmin3浏览0评论

I would like to show a message on my ASP.Net page like "Record saved" on save button click. After 5 seconds, I would like to hide it.
How can I do in JavaScript? Can I avoid to add jQuery (I'm not using it)?

I would like to show a message on my ASP.Net page like "Record saved" on save button click. After 5 seconds, I would like to hide it.
How can I do in JavaScript? Can I avoid to add jQuery (I'm not using it)?

Share Improve this question edited Jan 16, 2013 at 7:37 Himanshu 32.6k32 gold badges115 silver badges136 bronze badges asked Apr 28, 2011 at 8:25 stighystighy 7,17025 gold badges102 silver badges163 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

You could use the setTimeout function which allows you to defer the execution of a callback in the future. So you could place the following in the page:

<script type="text/javascript">
    window.setTimeout(function() {
        // This will execute 5 seconds later
        var label = document.getElementById('IdOfTheElementYouWantToHide');
        if (label != null) {
            label.style.display = 'none';
        }
    }, 5000);
</script>

Due to ID name mangling with ASP.NET you could use a class selector. And once you start doing this and your users start to ask you about adding some fade out effects you will quickly realize that a framework such as jQuery might e in handy.

You can use a JavaScript notification plugin Pines Notify

Look at that link to more choices

You can use the jGrowl add-in for jQuery - this provides "Mac-style" notifications for this kind of scenario.

发布评论

评论列表(0)

  1. 暂无评论