jQuery自动上传文件 [英] jQuery auto upload file

查看:353
本文介绍了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>

让我知道jQuery的技巧

Let me know the trick with jQuery

推荐答案

您可以在文件输入的onchange事件中提交表单,如下所示:

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

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

这篇关于jQuery自动上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆