选择要上传的文件后,我希望无需单击按钮即可将文件上传到数据库。这是如何使用 jQuery 完成的?
我想选择这样的文件: /image/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 上传文件的好方法,无需此处描述的 hack: http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/
关于javascript - 选择文件后开始上传,使用 jQuery。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6774143/