【发布时间】:2011-10-10 00:16:35
【问题描述】:
我有 HTML 页面,它提供了将文件上传到服务器的选项,服务器端有一个 servlet 操作类,它处理请求并写入文件。 这里是如何工作的
- 点击浏览文件并选择文件
- 点击提交按钮。
但我想在任何按钮上一键上传,请查看我的代码并建议如何使用 javascript/jQuery fn 进行上传。
<html> <head>
<script type = "text/javascript">
function test() {
var uploadfile = document.getElementByID("upload_id");
uploadfile.click(); // here i can browse the file without clicking on file brows button
} </script> </head> <body>
<input type="button" id="just_one_click" value ="click me" onclick="test();" />
<form action="upload.do" method="post" enctype="multipart/form-data">
<input type="file" id="upload_id" name = "fileupload" />
<input type = "submit" value="upload" />
</form> </body> </html>
【问题讨论】:
标签: javascript jquery servlets