【发布时间】:2016-02-12 02:03:09
【问题描述】:
我有一个 Iframe,它有一个带有文本字段的表单。这个表单是由 php 脚本创建的。父页面自动刷新,持续不断。
<form id="form" method="post" action="test.php?vid='.$vid.'">
<table border="1" width="100%" style="border-collapse:collapse">
<tr>
<th class="col-header list">Distance </th>
<th class="col-header list">Service</th>
<th class="col-header list">Recipient</th>
</tr>
<tr>
<td >
<input type="text" class="input" id="cdistance" name="cdistance" />
</td>
<td nowrap class="list">
<input type="text" class="input" id="service" name="service" />
</td>
<td nowrap class="list">
<input type="text" class="input" id="destination" name="destination" />
</td>
</tr>
<tr>
<td width="100%" colspan="3" style="background:#e0e0e0;">
<input type="submit" class="btn" name="add" id="add" value="Add New"/>
<input type="hidden" name="distance_unit" value="'.$distance.'" />
</td>
</tr>
</table>
</form>
为了避免用户输入的数据丢失(“点击提交之前”),我在父页面中使用查询代码来获取 Iframe 表单中输入的文本,并在页面刷新后将它们添加回文本字段。
我的问题是当用户在页面刷新文本字段未清除(表单未重置)但数据提交成功后点击提交按钮时。所以我尝试通过$('#form')[0].reset()重置表单。这是我得到的错误
未捕获的类型错误:无法读取未定义的属性“重置”
还尝试$('#textVal').val(''); 清空文本字段。但仍然是文本字段中的数据。
注意:如果用户在刷新之前点击提交按钮,则表单会被重置。有人需要更多详细信息,请告诉我。
对此的任何解决方案将不胜感激。
【问题讨论】:
-
您确定您的表单有
id="form"吗?.reset()应该可以工作,但您必须确保使用正确的选择器。 -
在此处发布您的表格。
-
@Growiel 是的,表单 ID 是正确的。
-
你能给我们提供一点你的 HTML 标记吗?
-
我在这里添加了部分表格。
标签: javascript php jquery html forms