我希望使用此代碼(從此處)淡出我的 Flash 消息:<script type="text/javascript">setTimeout(function() {$('#stepMessage').fadeOut('slow');}, 3000); </script>我的完整腳本如下所示:解決方案:在 base.html 中:{% 擴展 'bootstrap/base.html' %}{% block scripts %}<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> <-- included JQuery{% raw %}<script type="text/javascript">window.setTimeout(function() {$('#stepMessage').fadeOut('slow');}, 3000); </script> <-- added function{% endraw %}{% endblock %}{% extends "base.html" %}{% import 'bootstrap/wtf.html' as wtf %}在 index.html 中,我現在可以使用之前定義的函數:{% block content %} <div class="container"> . . . </div> {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for message in messages %} {% set lvl = "alert-danger" if message[1]["result"] == False else "alert-info" %} <div id="stepMessage" class="alert {{ lvl }}" role="alert">{{ message[1]["content"] }}</div> {% endfor %} {% endif %} {% endwith %} {% block app_content %} {% endblock %}{% endblock %}感謝@Rishi Dev 的幫助
<script> 在燒瓶 html 頁面中的位置
郎朗坤
2022-06-16 15:33:38