我正在开发一个允许用户上传图像文件的 JSP 页面。该文件稍后将保存在数据库中,并将用作他们的个人资料图像。如何通过单击 href 链接打开文件选择器对话框?
我知道 <input type = "file" />
解决方案,但这不是页面设计的一部分,我必须仅从 href 打开文件选择器。
最佳答案
试试这个,
<input type="file" id="upload" name="upload" style="visibility: hidden; width: 1px; height: 1px" multiple />
<a href="" onclick="document.getElementById('upload').click(); return false">Upload File</a>
查看工作 FIDDLE
也可以使用CSS效果来完成,
Read this link获取信息
关于javascript - 如何通过单击链接从 JSP 页面打开文件选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25174808/