admin管理员组

文章数量:1188795

I want the file input will automatic upload my image without enter any submit button.

<form action="/upload/" method="post" enctype="multipart/form-data">
  <input type="hidden" name="user_id" value="47" />
  <input type="file" name="upload" />
</form>

Let me know the trick with jQuery

I want the file input will automatic upload my image without enter any submit button.

<form action="/upload/" method="post" enctype="multipart/form-data">
  <input type="hidden" name="user_id" value="47" />
  <input type="file" name="upload" />
</form>

Let me know the trick with jQuery

Share Improve this question asked Dec 18, 2010 at 3:56 BlurBlur 1,2764 gold badges12 silver badges17 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 18

You can submit the form on the file input's onchange event, like this:

$("input[name=upload]").change(function() {
    $(this).closest("form").submit();
});

With more recent versions you can also just set the autoUpload option to true:

$('#fileupload').fileupload({ autoUpload: true });

本文标签: javascriptjQuery auto upload fileStack Overflow