在Flask应用程序中,我有一个包含多个字段的表单。有两个提交按钮,其中一个旨在仅提交字段1和2的信息(即使其他字段包含文本)。使用jQuery清除WTForm中的某些字段
我很不情愿地决定尝试在jQuery中做到这一点,我没有太多经验。考虑使用$ .post方法后,我决定使用$ .reset。
下面是我的一些代码:
(home.html做为)
<HEAD>
<script src="/static/scripts/jquery-3.2.1.js">
</script>
<script src="/static/scripts/reset.js">
</script>
<TITLE>My UI</TITLE>
</HEAD>
(单独的HTML文件从home.html的继承)
<form action="/" method="post">
<dl>
foo
{{ form.foo }}
bar
{{ form.bar }}
<form action="/" method="post"><p><input type=submit class="reset" value="Get Information">
Status
{{ form.status(class_="reset-this") }}
other
{{ form.other(class_="reset-this") }}
Frequency
{{ form.frequency(class_="reset-this") }}
</dl>
<p><input type=submit value=Update>
最后,我的JS:
$(function() {
$("button.reset").click(function() {
$(".resetThis").val("");
});
});
I t没有任何影响,当我运行该文件,并且当我尝试在JSFiddle中模拟它时,我得到一个Forbidden (403): CSRF verification failed. Request aborted.
错误。
有什么基本我失踪了?
我们可以看到小提琴吗? – randomguy04
当然!类似这样的:https://jsfiddle.net/joshf/g21knp5v/(表单在这里没有正确渲染,因为它在jinja2中,但“验证失败”错误重复。) –