Meh*_*d S 27 javascript jquery
选择要上传的文件后,我希望无需单击按钮即可将文件上载到数据库.这是如何使用jQuery完成的?
我想选择一个这样的文件:http: //i.stack.imgur.com/0408T.gif
<input type="file" valign="baseline" />
bin*_*ous 37
假设您正在使用表单:
// 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/
使用jQuery的插件uploadify
这是一个很棒的插件,它有很多选项,也可以自动上传
$(document).ready(function() {
  $('#file_upload').uploadify({
    'uploader'  : '/uploadify/uploadify.swf',
    'script'    : '/uploadify/uploadify.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder'    : '/uploads',
    'auto'      : true
  });
});