最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Flask closing flash message - Stack Overflow

programmeradmin2浏览0评论

I have flash message in my Flask app like this:

I want to if I click the close icon the flashed message is closing, or automatically closed in a set of time, eg: in 5 second it automatically closed.

Here is my _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>

So what do I need to improve my code to do that..?

PS: for more information, I using this nicely boilerplate.

I have flash message in my Flask app like this:

I want to if I click the close icon the flashed message is closing, or automatically closed in a set of time, eg: in 5 second it automatically closed.

Here is my _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>

So what do I need to improve my code to do that..?

PS: for more information, I using this nicely boilerplate.

Share Improve this question edited Aug 26, 2019 at 15:43 davidism 128k31 gold badges415 silver badges347 bronze badges asked Aug 26, 2019 at 15:07 TriTri 3,0596 gold badges41 silver badges73 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You can do this with jQuery. Add an onclick function to the button like so:

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

And here's the code to delete:

<script src="https://ajax.googleapis./ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
    function delete_flash(flash){
        $(flash).parent().remove()
    }
</script>
发布评论

评论列表(0)

  1. 暂无评论