我想在此旁边附加一个“浏览”按钮,只允许该按钮打开文件浏览器,但是如果单击div上的任何位置,则立即打开文件浏览器。有什么建议吗?
<div class="custom-file">
<input type="file" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
发布于 2019-02-26 21:16:46
引导程序的文件输入只是标签上的一个<input type="file">,该标签的样式看起来像一个输入字段;因此,当您单击" input“时,您单击的是label,它有一个引用input的for属性。
我认为您必须调整输入本身的样式,将其“放在”button之后,这样它才能像您想要的那样工作,并且移除标签对输入的引用,这样它就不会打开它。
.custom-file-input {
position: absolute !important;
z-index: 2;
width: 80px !important;
height: calc(1.5em + .75rem + 2px);
margin: 0;
opacity: 0;
right: 0;
}<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="custom-file">
<input type="file" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="">Choose file</label>
</div>
https://stackoverflow.com/questions/54894086
复制相似问题