最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Toggle alert from bootstrap - Stack Overflow

matteradmin8PV0评论

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);
Post a comment

comment list (0)

  1. No comments so far