为了隐藏(但保留功能)文件对话框中丑陋的默认输入类型文件按钮,我使用了以下机制:
HTML:
<label for="file-input">
<i class="fa fa-edit"></i> <!-- acts as file input on click-->
</label>
<input type="file" id="file-input" />
Run Code Online (Sandbox Code Playgroud)
CSS:
#file-input {
display: none; //hide the file input
}
Run Code Online (Sandbox Code Playgroud)
这符合预期:我单击 font Awesome 编辑图标,然后弹出文件对话框。
但是,当我使用按钮时,它会停止工作。单击按钮时没有看到文件对话框:
<label for="file-input">
<button type="button">Upload file</button> <!-- not working-->
</label>
<input type="file" id="file-input" />
Run Code Online (Sandbox Code Playgroud)