开发者

jQuery auto upload file

开发者 https://www.devze.com 2023-01-31 00:29 出处:网络
I want the file input will automatic upload my image without enter any submi开发者_如何转开发t button.

I want the file input will automatic upload my image without enter any submi开发者_如何转开发t 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


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 });
0

精彩评论

暂无评论...
验证码 换一张
取 消