使用jQuery选择文件后开始上传。 [英] Start upload after choosing a file, using jQuery.

查看:57
本文介绍了使用jQuery选择文件后开始上传。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选择要上传的文件后,我希望无需单击按钮即可将文件上传到数据库。如何使用jQuery完成?

After having chosen a file for upload, I want the file to be uploaded to database without the click of a button. How is this done using jQuery?

我想选择这样的文件:
http://i.stack.imgur.com/0408T.gif

I would like to choose a file like this: http://i.stack.imgur.com/0408T.gif

<input type="file" valign="baseline" />


推荐答案

假设您使用的是表格:

// select the file input (using a id would be faster)
$('input[type=file]').change(function() { 
    // select the form and submit
    $('form').submit(); 
});

编辑: 要使此答案保持最新状态:

有一种很好的方法可以通过AJAX上传文件而不用这里描述的黑客:
http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/

There is a nice way to upload files via AJAX without hacks described here: http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/

这篇关于使用jQuery选择文件后开始上传。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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