javascript 一键上传文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11412284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Upload File with one button
提问by Filippo Alessi
How can I make a button in the html you need to send files that allow you to select the file and then sending it on the page that I want without using a button to select the file and a button to send it to another page? Thanks you!
如何在 html 中制作一个按钮,您需要发送文件,允许您选择文件,然后将其发送到我想要的页面上,而无需使用按钮选择文件和按钮将其发送到另一个页面?谢谢!
回答by kapa
<form>
<input type="file" onchange="this.form.submit()" />
</form>
回答by Mateusz Rogulski
You should use
你应该使用
HTML
HTML
<form id="form">
<input type="file" id=file"/>
</form>
more info: http://www.w3.org/wiki/HTML/Elements/input/file
更多信息:http: //www.w3.org/wiki/HTML/Elements/input/file
Jquery
查询
$("#file").onchange(function () {
$("#form").submit();
});