我有一个带有文本字段的窗体的Iframe。此窗体由php脚本创建。父页面不断自动刷新。窗体重置不会在页面auot刷新后发生
<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()
。这是我
Uncaught TypeError: Cannot read property 'reset' of undefined
也试过$('#textVal').val('');
空文本字段错误。但仍然保留在文本字段中的数据。
注意:如果用户在刷新前点击提交按钮,表单将被重置。有没有人需要更多的细节,请让我知道。
任何解决方案,这将不胜感激。
你确定你的表单有一个'id =“form”'? '.reset()'应该可以工作,但是你必须确保你使用了正确的选择器。 – Growiel
在这里发表你的表格。 –
@Growiel是表单ID是否正确。 –