2011-07-29 86 views

回答

4

我认为你需要创建一个HTML表单和输入追加到形式,如果你需要提交,您可以通过提交按钮或通过$ .submit

# from http://www.daimi.au.dk/~u061768/file-input.html 
    <script type="text/javascript"> 
$(function() { 
    $('button').button().add('#foo, a').file().choose(function(e, input) { 
     $(input).appendTo('#TheForm'). 
         attr('name', 'a-name'). 
         attr('id', 'an-id'); 
    }); 


}); 
    </script> 
    ... 
    <form method="post" enctype="multipart/form-data" id="TheForm" action="/path/in/your/server/"> 
    <input type="submit" value="send"> 
    </form> 

反正这个做不是通过ajax提交文件的最佳插件。

+0

我不需要ajax上传,我只需要在我的表单中使用自定义元素作为文件上传字段。你有任何插件推荐? – applechief

+0

但你需要什么? – sacabuche

+0

可能是你正在使用的插件是你需要的,看到这个代码http://jsfiddle.net/m7Rj8/ – sacabuche

0

上传本身不属于这个插件的范围。你应该看到你的服务器端技术。

+0

明白了。但是这个插件所做的就是调出一个文件选择器并将选中的文件存储在一个变量中。如何在表单中插入该变量并让它提交服务器端? – applechief