您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Flask中执行耗时的功能时显示“正在加载”消息

在Flask中执行耗时的功能时显示“正在加载”消息

将此添加到你的index.html或js文件中(我假设你在这里有jQuery,你当然可以使用标准javascript。):

<script type="text/javascript">// <![CDATA[
        function loading(){
            $("#loading").show();
            $("#content").hide();       
        }
// ]]></script>

将此添加到你的html或css文件中:

div#loading {
    width: 35px;
    height: 35px;
    display: none;
    background: url(/static/loadingimage.gif) no-repeat;
    cursor: wait;
    }

然后更改你的提交按钮以调用上面的js函数

<input type="submit" name="anything_submit" value="Submit" onclick="loading();">

并在你的基本html文件添加加载内容内容div:

<body>
    <div id="loading"></div>
    <div id="content">
        <h3>Type anything:</h3>
        <p>
        <form action="." method="POST">
            <input type="text" name="anything" placeholder="Type anything here">
            <input type="submit" name="anything_submit" value="Submit" onclick="loading();">
        </form>
        </p>
    </div>    
</body>

现在,当你单击“提交”时,js函数应隐藏你的内容显示加载的GIF。这将一直显示,直到处理完你的数据并且flask加载新页面为止。

Python 2022/1/1 18:24:22 有447人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶