我試圖在用戶選擇文件後立即啓動文件的上傳。該表單應該消失,取而代之的是「上傳圖片...」消息。jQuery提交表單上的文件選擇不起作用
到目前爲止,我所得到的只是被隱藏的表單(和消息顯示),但上傳並未發生。該表格未提交。任何想法爲什麼?
這是JS
<script>
$(function(){
$("#file_select").change(function(){
$(this).parents("#upload_form").submit();
$("#upload_form_div").hide();
$("#loading").show();
});
});
</script>
和HTML
<div class="float_left" id="upload_form_div">
<h3>Select a picture for your profile (4 MB max):</h3>
<form action="http://example.com/profile/upload_picture"
id="upload_form"
enctype="multipart/form-data"
method="post" accept-charset="utf-8">
<input type="file" name="userfile"
id="file_select" />
<input type="hidden" name="upload" value="upload" />
<button id="submit" type="submit"><img height="24" width="24"
alt="Upload" src="images/icons/small/white/bended%20arrow%20right.png">
<span>Upload</span>
</button>
</form>
<form action="http://example.com/profile/remove_picture"
method="post" accept-charset="utf-8">
<button type="submit"><img height="24" width="24"
alt="Remove" src="images/icons/small/white/trashcan.png">
<span>Remove</span>
</button>
</form>
</div>
<div id="loading" style="display:none;">
Uploading your picture...
</div>
我加入到我的回答如下 - 在這裏解決了這個問題對我來說:http://jsfiddle.net/q3J4R/ – willoller 2011-04-21 15:54:48