我想重置表單,其ID爲user_post
。此表單也包含隱藏字段。 我用這個代碼復位輸入表單字段爲什麼當我在表單元素上執行重置方法時,我的隱藏字段未被重置?
$('#user_post').each(function(){
this.reset();
});
我的形式給出波紋管
<form enctype="multipart/form-data" id="user_post" action="/****/index.php/site/username" method="post">
<div class="tab-content">
<div id="tab-1" >
<textarea rows="3" placeholder="Share what have been up to...." name="Userpost[usertxtpost]" id="Userpost_usertxtpost"></textarea>
</div>
<div id="tab-2" >
<textarea rows="1" placeholder="Title...." name="Userpost[title]" id="Userpost_title"></textarea>
<input id="Userpost_image" type="hidden" value="" name="Userpost[image]" />
<input tabindex="21" name="Userpost[image]" id="Userpost_image" type="file" />
<input name="Userpost[imagename]" id="Userpost_imagename" type="hidden" />
<textarea rows="3" placeholder="about this image...." name="Userpost[coment]" id="Userpost_coment"></textarea>
</div>
<div id="tab-3" class="tab-pane row-fluid fade">
<input name="Userpost[video_title]" id="Userpost_video_title" type="hidden" />
<textarea rows="1" placeholder="Copy and paste video url...." name="Userpost[video]" id="Userpost_video"></textarea>
<input name="Userpost[video_text]" id="Userpost_video_text" type="hidden" />
</div>
<div id="tab-4" >
<input rows="3" placeholder="Share url...." name="Userpost[link]" id="Userpost_link" type="text" maxlength="200" />
<input name="Userpost[url_title]" id="Userpost_url_title" type="hidden" />
<input name="Userpost[url_text]" id="Userpost_url_text" type="hidden" />
<input name="Userpost[url_image]" id="Userpost_url_image" type="hidden" />
</div>
<input value="121" name="Userpost[user_id]" id="Userpost_user_id" type="hidden" />
<button type="button" id="submitTimelinePosts">SUBMIT </button>
</div>
</form>
也許他基於與其他表單元素的交互改變了隱藏字段的值? – crush
是的,我也這麼認爲!例如,可能是顏色選擇器或日曆 – alex
您的第一批代碼不會執行任何OP代碼尚未執行的操作。答案的第二部分是*解*,但它並不尊重隱藏字段的原始值。 – crush