页面加载时的 Flask 加载图标
Flask loading icon on page load
from flask import Flask, render_template, Response, request, redirect, url_for
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route("/", methods=["POST", "GET"])
def index():
if request.method == "POST":
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True)
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<style>
div#loading {
width: 50px;
height: 50px;
display: none;
background: url('https://i.giphy.com/3oEjI6SIIHBdRxXI40.gif') center no-repeat;
cursor: wait;
padding-left:100%;
}
</style>
</head>
<body>
<form method="POST">
<input type="text">
<button type="submit" onclick="loading();">
<div id="loading"></div>
<div id="content">
<i class="fas fa-search"></i>
</div>
</button>
</form>
<script type="text/javascript">
function loading(){
$("#loading").show();
$("#content").hide();
}
</script>
</body>
</html>
我正在构建一个 Flask 应用程序,当您按下按钮时,加载程序应该将搜索玻璃图标替换为加载 gif。
目前,单击按钮时未显示 gif。
当我从加载样式中删除 display:none
时,gif 出现了,所以我知道它在那里。
您正在使用 JQuery 来显示和隐藏元素,但您尚未将其包含在模板中。
因此包含一个脚本标签,例如
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
在您引用的脚本标记之前 JQuery
我想我已经有了一个 div id = content
,所以它删除了整个 div。记得检查您的身份证件!
from flask import Flask, render_template, Response, request, redirect, url_for
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route("/", methods=["POST", "GET"])
def index():
if request.method == "POST":
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True)
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<style>
div#loading {
width: 50px;
height: 50px;
display: none;
background: url('https://i.giphy.com/3oEjI6SIIHBdRxXI40.gif') center no-repeat;
cursor: wait;
padding-left:100%;
}
</style>
</head>
<body>
<form method="POST">
<input type="text">
<button type="submit" onclick="loading();">
<div id="loading"></div>
<div id="content">
<i class="fas fa-search"></i>
</div>
</button>
</form>
<script type="text/javascript">
function loading(){
$("#loading").show();
$("#content").hide();
}
</script>
</body>
</html>
我正在构建一个 Flask 应用程序,当您按下按钮时,加载程序应该将搜索玻璃图标替换为加载 gif。
目前,单击按钮时未显示 gif。
当我从加载样式中删除 display:none
时,gif 出现了,所以我知道它在那里。
您正在使用 JQuery 来显示和隐藏元素,但您尚未将其包含在模板中。
因此包含一个脚本标签,例如
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
在您引用的脚本标记之前 JQuery
我想我已经有了一个 div id = content
,所以它删除了整个 div。记得检查您的身份证件!