HTML 文件上传“未选择文件"文字样式

编程入门 行业动态 更新时间:2024-10-12 01:26:39
本文介绍了HTML 文件上传“未选择文件"文字样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个需要文件上传的 html 表单.当我让文件上传部分工作时,我无法获得表单上传按钮的样式和未选择文件"文本.

I am building a html form that needs file upload. While I got the file upload part working, I am unable to get the styling of form upload button and " No file selected" text.

我想要的标记是

有办法吗?

PS:请忽略绿色文字(上传屏幕截图").我有那个工作.

PS: Please ignore the green text ( "Upload a screen shot"). I have that working.

按钮的当前行为和未选择文件"在同一行.

Current behavior the button and the "no file chosen" is in the same line.

HTML 代码:

<div class="formField"> <label for="fileToUpload">Upload a screen shot (optional) </label> <input type="file" name="fileToUpload" id="fileToUpload"/> </div>

推荐答案

文件输入不能单独使用 CSS 设置样式.您需要使用一个 jQuery 插件来制作一个可以使用 CSS 设置样式的自定义文件上传按钮.

File inputs can't be styled with CSS alone. You'll need to use a jQuery plugin that makes a custom file upload button that can be styled with CSS.

一个很好的叫做 NiceFileInput.

使用方法:

<script src="ajax.googleapis/ajax/libs/jquery/1.7.0/jquery.min.js"></script> <script src="/your_path/jquery.nicefileinput.min.js"></script>

从这里下载文件.p>2.将其绑定到您想要的元素.这会将其绑定到所有文件输入:

<script type="text/javascript"> $(document).ready(function() { $("input[type=file]").nicefileinput(); }); </script>

3.用 CSS 自定义它

.NFI-wrapper { // the container div } .NFI-button { // the button div element } .NFI-filename { // the text input element which collects and shows the value }

更多推荐

HTML 文件上传“未选择文件"文字样式

本文发布于:2023-10-19 18:53:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508450.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:样式   文件上传   文字   文件   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!