flask框架在searchhtml中增加更新按钮用于调用后台homecodercolrenamepy脚本并返回输出结果。nnn!DOCTYPE-htmlnhtmlnheadn----meta-charset=utf-8n----titleSearchtitlen----stylen-----设置页面基本样式-n----body-n--------font-family-Microsoft-Yahei;n----nn-----n----search_box-n--------width-500p
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Search</title>
<style>
/* 设置页面基本样式 */
body {
font-family: 'Microsoft Yahei';
}
<pre><code>/* */
.search_box {
width: 500px;
margin: 0 auto;
text-align: center;
}
.search_input {
width: 200px;
height: 30px;
line-height: 30px;
border: 1px solid #ccc;
border-radius: 4px;
padding: 0 10px;
font-size: 14px;
}
.search_btn {
width: 60px;
height: 32px;
line-height: 32px;
margin-left: 10px;
background-color: #00a2d4;
color: rgb(183, 248, 248);
border: none;
border-radius: 4px;
font-size: 14px;
}
.update_btn {
width: 60px;
height: 32px;
line-height: 32px;
margin-left: 10px;
background-color: #00a2d4;
color: rgb(183, 248, 248);
border: none;
border-radius: 4px;
font-size: 14px;
}
</style>
</code></pre>
</head>
<body><body>
<form action="/search" method="post" class="search_box" style="margin: 0 auto;display: flex;justify-content: center;">
<div style="margin-bottom: 8px; padding-left:5px;">
<input type="text" name="number" class="search_input" placeholder="请输入“番号”">
<input type="text" name="actor" class="search_input" placeholder="请输入“演员”">
<input type="text" name="type" class="search_input" placeholder="请输入“类型”">
</div>
<div>
<input type="submit" class="search_btn" value="搜索">
<input type="button" class="update_btn" value="更新" onclick="updateData()">
</div>
</form>
</body>
<script>
function updateData() {
fetch('/update')
.then(res => res.text())
.then(data => alert(data))
.catch(error => console.log(error));
}
</script>
</html>
原文地址: https://www.cveoy.top/t/topic/sqC 著作权归作者所有。请勿转载和采集!