烧瓶关闭提示信息

时间:2019-08-26 15:07:57

标签: javascript html

我的 Flask 应用中有Flash消息,如下所示: enter image description here

我想如果我单击关闭图标,则闪烁的消息正在关​​闭,或者在一段时间内自动关闭,例如:5秒钟后它会自动关闭。

这是我的 _flash.html

{% macro render_flashes(class) %}
    {% with msgs = get_flashed_messages(category_filter=[class]) %}
        {% for msg in msgs %}
            <div class="ui {{ class }} message">
                <i class="close icon"></i>
                {{ msg }}
            </div>
        {% endfor %}
    {% endwith %}
{% endmacro %}

<div class="ui text container">
    <div class="flashes">
        {{ render_flashes('error') }}
        {{ render_flashes('warning') }}
        {{ render_flashes('info') }}
        {{ render_flashes('success') }}
    </div>
</div>

那我需要改进我的代码来做到这一点吗??

PS :有关更多信息,我很好地使用了boilerplate

1 个答案:

答案 0 :(得分:2)

您可以使用jQuery完成此操作。像这样向按钮添加一个onclick函数:

<i class="close icon" onclick=delete_flash(this)></i>

这是要删除的代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
    function delete_flash(flash){
        $(flash).parent().remove()
    }
</script>
相关问题