【问题标题】:How to remove "Choose File" button from the textbox?如何从文本框中删除“选择文件”按钮?
【发布时间】:2019-09-13 09:46:26
【问题描述】:

如何在文本框中隐藏选择文件按钮,因为我正在使用另一个按钮进行浏览。

如果我提供type="File",按钮"choose file" 会自动出现在我的文本框中。 代码如下:

 <div class="col-lg-6">
    <label>Select File</label>
    <input  type="file"  id="SelectFile" @*style="display: none;"*@ class="form-control  input-sm input-small input-inline" />
</div>
 <div class="btn-group">
     <button id="btnBrowse" name="btnBrowse" onclick="document.getElementById('SelectFile').click();"  class="btn btn-block btn-primary btn-flat"><span class="hide-on-mobile">Browse </span><i class="fa fa-search"></i></button>
 </div>

Image with Choose File button

我尝试提供*style="display: none;"*,这使我的文本框不可见。

Image after apply style none:

【问题讨论】:

    标签: javascript html file-upload filebrowse


    【解决方案1】:

    在这里您可以做的是从输入文件中删除类并将它们添加到您的标签中,然后将 'hidden' 或 display:none 属性添加到文件输入中

     <div class="col-lg-6">
        <label class="form-control  input-sm input-small input-inline" >Select File</label>
        <input  type="file" hidden  id="SelectFile"  />
    </div>
    

    【讨论】:

    • 先生,隐藏对我不起作用,我已经尝试过 style="display: none;",这会使我的文本框不可见。我也附上了有问题的图片
    • 我已经更改了脚本。请检查
    【解决方案2】:

    这是浏览器的默认行为。如果你仍然想改变它,你也可以这样做。请参考,from this link

    【讨论】:

    • 我参考了这些答案,但无法得到正确答案,所以我在单独的问题中问了先生......
    【解决方案3】:

    我认为你的问题是重复的; How to remove “Choose File” button from the textbox?

    但是,在您的 CSS 中,您可以尝试类似的方法;

    #SelectFile {
      padding: 36px 0 0 0;
    }
    

    【讨论】:

    • 先生,您从文本框中删除了我的选择文件按钮,但是使用浏览按钮选择文件后,它永远不会将文件名传递给我的文本框..
    • 实现您想要做的事情的一种方法是将两个 div 包装在一个 div 中,并使该 div 的位置相对,按钮 div 的位置绝对。然后您可以根据需要调整按钮的位置。您可以查看此 codepen 链接并告诉我它是否符合您的要求,以便我更新我的答案。 codepen.io/hussamhassan/pen/aboKjPK
    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    相关资源
    最近更新 更多