【问题标题】:Bootstrap Auto Close Dynamically Added AlertBootstrap 自动关闭动态添加的警报
【发布时间】:2016-07-07 22:17:45
【问题描述】:

所以我在用户单击按钮时动态添加此代码(data 作为 AJAX 调用的参数传入,一切正常):

$('#container').append('
<div class=" alert alert-danger alert-dismissable fade in" role="alert">    
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    <h4>Error</h4>
    <p>'+data+'</p>
</div>');`

我想知道是否可以添加功能以在特定时间后自动关闭此警报。我知道还有其他方法可以做到这一点,我可以很容易地做到这一点,我只是想这样做,因为我希望在单击同一个按钮时有多个警报,所以让每个警报自己处理并消失会自动让它看起来更干净。

【问题讨论】:

    标签: javascript jquery twitter-bootstrap


    【解决方案1】:

    听起来你可以使用 setTimeout Javascript 函数: https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout

    【讨论】:

    • 虽然理论上这可以回答这个问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
    猜你喜欢
    • 1970-01-01
    • 2023-04-01
    • 2011-11-30
    • 2011-12-01
    • 2014-05-30
    • 2014-12-12
    • 1970-01-01
    • 2017-09-01
    • 2016-09-09
    相关资源
    最近更新 更多