简体   繁体   English

寻找最有效的方法来将取消时的表单值恢复为原始值

[英]Looking for most efficient way to revert form values to original values on cancel

I have a form with a dynamically-generated group of fields - backend is php/mySQL, and the form is created by reading in data from a table and creating a group of fields for each record. 我有一个带有动态生成的字段组的表单-后端是php / mySQL,通过从表中读取数据并为每个记录创建一组字段来创建表单。 The form has a bit of javascript onSubmit that confirms whether the user really wants to save their changes, but I'm having trouble reverting to the original values if they say that they don't want to save. 表单中有一些javascript onSubmit可以确认用户是否真的要保存他们的更改,但是如果他们说不想保存,则我很难恢复到原始值。 Reloading the page from the database is not an option. 无法从数据库重新加载页面。

Unless you're doing something wildly unconventional, try: 除非您正在做一些非常常规的事情,否则请尝试:

<input type="reset" value="Cancel" />

Or if you need to do it in javascript: 或者,如果您需要使用javascript:

document.yourform.reset()

如果无法往返服务器,我想说的唯一解决方法是将表单字段的原始值保留在javascript中(变量,数组,最有意义的变量)并使用这些将重新填充表单字段。

On the initial loading of the form store the values in "hidden" input fields. 在初始加载表单时,将值存储在“隐藏”输入字段中。 Use the values of these hidden fields when you cancel the form. 取消表单时,请使用这些隐藏字段的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM