【发布时间】:2022-01-11 00:25:32
【问题描述】:
我开发了一个 Python/Flask 应用程序,但在实现 Bootstrap 警报时遇到了问题,其想法是:
- 可通过关闭按钮关闭。
- 如果不采取任何操作,则在 2 秒后淡出并关闭。
代码
<div class="container">
{% for message in get_flashed_messages() %}
<script>
function close_alert()
{
document.getElementById("my_alert").close()
}
setTimeout("close_alert()", 2000)
</script>
<div id="my_alert" class="alert alert-primary alert-dismissible fade show" role="alert">
<strong>{{message}}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
</div>
我是 Bootstrap 的新手,如果能得到任何支持,我将不胜感激!
谢谢!
【问题讨论】:
-
您可以在 close_alert 函数中使用
.hide()而不是.close()。
标签: javascript html twitter-bootstrap alert auto-close