Bootstrap 文件输入:修改文件选择器显示
使用 Bootstrap 4 的文件浏览器时,您可能会遇到显示默认“Choose”的问题文件...”文本。此文本是在 .custom-file-control 元素中使用 CSS 设置的,使用 JavaScript 很难对其进行修改。
Bootstrap 5
在 Bootstrap 5 中,自定义文件输入已被删除。因此,修改文件选择器显示需要自定义 CSS 或 JavaScript 技术。
Bootstrap 4.4
要在 Bootstrap 4.4 中显示所选文件名,可以使用 JavaScript:
<code class="javascript">document.querySelector('.custom-file-input').addEventListener('change',function(e){ var fileName = document.getElementById("myInput").files[0].name; var nextSibling = e.target.nextElementSibling; nextSibling.innerText = fileName; });</code>
Bootstrap 4.1
在 Bootstrap 4.1 及以上版本中,“选择文件...”占位符在 .custom-file-label 元素中设置:
<code class="html"><label class="custom-file-label" for="exampleInputFile"> Select file... </label></code>
可以使用CSS更改按钮文本:
<code class="css">.custom-file-input ~ .custom-file-label::after { content: "Button Text"; }</code>
原始答案(Bootstrap 4 Alpha 6)
修改初始占位符和按钮文本,可以使用 CSS:
<code class="css">#customFile .custom-file-control:lang(en)::after { content: "Select file..."; } #customFile .custom-file-control:lang(en)::before { content: "Click me"; }</code>
要检索所选文件名并更新显示,可以使用 JavaScript:
<code class="javascript">$('.custom-file-input').on('change',function(){ var fileName = $(this).val(); });</code>
但是,由于占位符文本是伪元素,JavaScript无法直接修改它。解决方法是添加一个隐藏伪内容的 CSS 类,并将文件名放在 .form-control-file 范围中:
<code class="css">.custom-file-control.selected:lang(en)::after { content: "" !important; }</code>
<code class="javascript">$('.custom-file-input').on('change',function(){ var fileName = $(this).val(); $(this).next('.form-control-file').addClass("selected").html(fileName); });</code>
以上是如何修改Bootstrap中的文件选择器显示?的详细内容。更多信息请关注PHP中文网其他相关文章!

重构自己的代码看起来是什么样的?约翰·瑞亚(John Rhea)挑选了他写的一个旧的CSS动画,并介绍了优化它的思维过程。

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatoryand and powerincreatingsmoothcssanimations.keytricksinclude:1)definingsmoothtransitionsbetnestates,2)使用AnimatingmatematingmultationmatingMultationPropertiessimultane,3)使用使用4)使用BombingeNtibalibility,4)使用BombingingWithjavofofofofofoffo

CSSCOUNTERSAREDOMANAGEAUTOMANAMBERINGINWEBDESIGNS.1)他们可以使用forterablesofcontents,ListItems,and customnumbering.2)AdvancedsincludenestednumberingSystems.3)挑战挑战InclassINCludeBrowsEccerCerceribaliblesibility andperformiballibility andperformissises.4)创造性

使用滚动阴影,尤其是对于移动设备,是克里斯以前涵盖的一个微妙的UX。杰夫(Geoff)涵盖了一种使用动画限制属性的新方法。这是另一种方式。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

Dreamweaver Mac版
视觉化网页开发工具