javascript – jQuery在一定时间后删除bootstrap警报

前端之家收集整理的这篇文章主要介绍了javascript – jQuery在一定时间后删除bootstrap警报前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用示例中的动态引导警报.见下文.

如何添加超时功能,以便在X时间后警报自动关闭

HTML

JQUERY:

bootstrap_alert = function() {
    }
bootstrap_alert.warning = function(message) {
    $('#alert_placeholder').append('
最佳答案
创建一个删除第一个(因此,最旧的)警报的函数

function alertTimeout(wait){
    setTimeout(function(){
        $('#alert_placeholder').children('.alert:first-child').remove();
    },wait);
}

[0]确保每次超时仅删除第一个警报.

然后在显示警报时调用函数,参数是警报关闭时间长度,以毫秒为单位:

bootstrap_alert.warning = function(message) {
    $('#alert_placeholder').append('

请看这jsFiddle

原文链接:https://www.f2er.com/jquery/428698.html

猜你在找的jQuery相关文章