Javascript <a> 标签上的打开文件对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10216331/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:21:16  来源:igfitidea点击:

Open File Dialog box on <a> tag

javascripthtml

提问by kaur

I want to have an Open Filedialog box on a link in my webpage.

我想Open File在我的网页中的链接上有一个对话框。

I tried

我试过

<input name="uploadedfile" type="file">

but, it works as a button. And, doesn't allow to select multiple files.

但是,它作为一个按钮工作。并且,不允许选择多个文件。

I want to have something like

我想要类似的东西

<a href="#" onclick="some_function_for_OpenFileDialogBox">Upload Files</a>

Please suggest.

请建议。

Thank You

谢谢你

Kaur

考尔

回答by d4rkpr1nc3

You can only open a "Open File" dialog using a input type=file tag. However the efect you are looking for can be accomplished like this :

您只能使用 input type=file 标签打开“打开文件”对话框。但是,您正在寻找的效果可以这样完成:

<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</a>