相关疑难解决方法(0)

无法打开标签内带有按钮的文件对话框

为了隐藏(但保留功能)文件对话框中丑陋的默认输入类型文件按钮,我使用了以下机制:

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)

html css

3
推荐指数
1
解决办法
2531
查看次数

标签 统计

css ×1

html ×1