我有一個帶有文本字段的窗體的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是否正確。 –