javascript - 表单在提交发布请求时被清除
问题描述
我想防止我的表单在烧瓶中的发布请求中被清除。这是我的代码:
预测器.html
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="static/vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="static/fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="static/vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="static/vendor/select2/select2.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="static/vendor/perfect-scrollbar/perfect-scrollbar.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="static/css/util.css">
<link rel="stylesheet" type="text/css" href="static/css/main.css">
</head>
<body>
<form method="POST" id="Formid">
<div class="form-group" onsubmit="return false">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Sepal length">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Sepal Width">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Petal length">
<input type="text" class="form-control input-sm" id="input" name="data_input" style="width:100%" maxlength="500"placeholder="Petal Width">
<button type="submit" class="btn btn-success" value="Submit" method="get"><i class="fa fa-search" aria-hidden="true"></i></button>
{{predictions}}
</div>
</form>
</body>
</html>
这是提交表单的示例,我得到输出,但表单值被清除
解决方案
如果我猜对了,您需要保留表单中其他字段的值,如果表单由于一个或多个无效input
而无法处理。input
在发布请求之后,将有效input
字段的值存储在变量中并将它们传递到标签中的value
属性中,input
以便在下次重新加载时预填充表单的输入。
像这样<input type="text" value="{{ some_variable }}" />
您最初可以将这些变量设置为空字符串,以便用户首次输入。
推荐阅读
- php - Woocommerce 变量订阅自定义字段复选框将默认设置为未选中
- python - 如何在函数定义中使用列表元素作为输入?
- vector - 在 CAPL CANalyzer 中使用 struct
- javascript - d3 时间线图表有大量标签,因此它们重叠。如何根据图表大小有选择地显示标签?
- svg - react-native-svg:SVG 图标内的自定义文本
- hyperledger-fabric - 无法注册管理员用户:错误:调用注册端点失败并出现错误 [错误:套接字挂断]
- angular - 将鼠标悬停在绘制的多边形上时 Mapbox 显示区域
- reactjs - 为什么我的 React 组件列表在使用 Index 作为 key prop 时不会弄乱?
- javascript - 句点、单词和冒号的正则表达式
- c++ - 无法在 C++ 中使用计数作为全局变量