javascript 提交值后如何清除表单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5280807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:37:34  来源:igfitidea点击:

How to clear the form after submitting the values?

javajavascriptjspstruts

提问by priya

I have a form with few filed. Once i submit the form the data is stored in database and i will return to the same page. Now, How to clear the fields in the form??

我有一个很少提交的表格。一旦我提交表单,数据就会存储在数据库中,我将返回到同一页面。现在,如何清除表单中的字段?

It is a struts based application. On submit it does some validations using java script then forwarded to the same page. Now, I must get a fresh page. I mean the fields must be cleared.

它是一个基于支柱的应用程序。在提交时,它使用 java 脚本进行一些验证,然后转发到同一页面。现在,我必须得到一个新的页面。我的意思是必须清除这些字段。

采纳答案by Buhake Sindi

You can override Struts' Action reset()method and after you used it in your action you can do form.reset(request, response);and do a forward. That way, your form is resetted.

您可以覆盖 Struts 的 Actionreset()方法,在您的操作中使用它之后,您可以执行form.reset(request, response);并执行转发。这样,您的表单将被重置。

回答by Buhake Sindi

you can clear the form with the resetmethod of your form.

您可以使用表单的重置方法清除表单。

回答by sereivuth

You can use redirect method like this :

您可以使用这样的重定向方法:

request.setStatus(request.SC_SEE_OTHER);
request.setHeader("Location",url);

Where SC_SEE_OTHER is the proper 303 code and "url" is the url of you current page this will reload your page so all your filed will be reset.

其中 SC_SEE_OTHER 是正确的 303 代码,“url”是您当前页面的 url,这将重新加载您的页面,因此您的所有文件都将被重置。

回答by vinis

In my case i handle in java action class , you should clear the model or bean object in your java class before return Action.SUCCESS; example customerDetail.setId(""); customerDetail.setName("");

在我的情况下,我在 java 操作类中处理,您应该在返回 Action.SUCCESS 之前清除 java 类中的模型或 bean 对象;示例 customerDetail.setId(""); customerDetail.setName("");

回答by Brad Mace

Can't you just use the javascript reset()method on the form?

你不能只reset()在表单上使用 javascript方法吗?

回答by rain

You can have 2 options use on load JavaScript form.reset() or you can clear your formclass fields before returning to your form ie define a reset method in your struts form class call this method before return.

您可以在加载 JavaScript form.reset() 时使用 2 个选项,或者您可以在返回表单之前清除表单类字段,即在您的 struts 表单类中定义一个重置方法,在返回之前调用此方法。