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

javascript - Toggle alert from bootstrap - Stack Overflow

programmeradmin1浏览0评论

Im using the following alert and I want it to be toggle after 2 sec,how should I do that ?

    <div class="alert alert-info">
        <a href="#" class="close" data-dismiss="alert">&times;</a>
        data was saved
    </div>

Im using the following alert and I want it to be toggle after 2 sec,how should I do that ?

    <div class="alert alert-info">
        <a href="#" class="close" data-dismiss="alert">&times;</a>
        data was saved
    </div>
Share Improve this question asked Jul 10, 2014 at 11:41 07_05_GuyT07_05_GuyT 2,88715 gold badges48 silver badges92 bronze badges 4
  • Have you tried setTimeout()? – RevanProdigalKnight Commented Jul 10, 2014 at 11:43
  • @RevanProdigalKnight-how can you provide example? – 07_05_GuyT Commented Jul 10, 2014 at 11:44
  • 1 Using jQuery: setTimeout(function() {$('.alert.alert-info').toggle(); },2000); – RevanProdigalKnight Commented Jul 10, 2014 at 11:46
  • Did you use the default way for bootstrap to enable the alert? – ImAtWar Commented Jul 10, 2014 at 11:53
Add a ment  | 

4 Answers 4

Reset to default 4
$('#alert').fadeIn('slow').delay(2000).fadeOut('slow');

JSBin Example

You can do that with setTimeout like:

setTimeout(function() {
        // Do something after 2 seconds
        $('.alert').show();
    }, 2000);

The .alert should be display:none; by default.

use a setTimeout :

setTimeout(function() {
    $('.alert-info').hide();
}, 2000);

see demo -> http://jsfiddle/JAFmx/

For the default way, as is described on their website:

http://getbootstrap./javascript/

setTimeout(function() {
$(".alert").alert('close')
}, 2000);
发布评论

评论列表(0)

  1. 暂无评论