<input type="file" name="feedbackFile" id="feedbackFile">怎么做美化,并且可以显示文件名
时间: 2023-07-19 17:36:18 浏览: 56
您可以通过以下方式美化上传文件的 input 元素,并显示上传的文件名:
1. 隐藏默认样式的 input 元素
```css
input[type="file"] {
display: none;
}
```
2. 使用样式更好看的 label 元素代替 input 元素
```html
<label for="feedbackFile" class="file-label">
<i class="fa fa-upload"></i>
选择文件
</label>
<input type="file" name="feedbackFile" id="feedbackFile">
```
3. 监听文件选择事件,获取文件名并显示
```javascript
var fileInput = document.getElementById('feedbackFile');
var fileLabel = document.querySelector('.file-label');
fileInput.addEventListener('change', function() {
var fileName = this.value.split('\\').pop(); // 获取文件名,去掉路径
fileLabel.innerText = fileName || '选择文件'; // 如果没有选择文件,则显示默认文本
});
```
4. 美化 label 元素的样式
```css
.file-label {
display: inline-block;
padding: 10px;
color: #fff;
background: #007bff;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
}
.file-label:hover {
background: #0062cc;
}
.fa-upload {
margin-right: 5px;
}
```
这样,您就可以美化上传文件的 input 元素,并在用户选择文件后显示文件名了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<input type="text" oninput="filterTable(1)" placeholder="aoiStep" >
<input type="text" oninput="filterTable(2)" placeholder="defectType" >
<input type="text" oninput="filterTable(3)" placeholder="layerCode" >
<input type="text" oninput="filterTable(4)" placeholder="type">
<input type="text" oninput="filterTable(5)" placeholder="dpet" >
<input type="text" oninput="filterTable(6)" placeholder="subcode" >
<input type="text" placeholder="codeDescription" >
image1
image2
image3
image4
image5
<input type="text" placeholder="determination_rule">
<input type="text" name="aoi_step" value="3">
<input type="text" name="defect_type" value="Particle">
<input type="text" name="layer_code" value="ACT">
<input type="text" name="type" value="Particle">
<input type="text" name="dpet" value="ACT">
<input type="text" name="subcode" value="Particle">
<input type="text" name="code_description" value="ACT">
<input type="file" name="image1_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;">
<input type="file" name="image2_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;">
<input type="file" name="image3_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;">
<input type="file" name="image4_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;">
<input type="file" name="image5_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;">
Particle 网页表格内的数据上传到phpstudy创建的数据库,image1-image5为图片,上传时需要将图片保存在本地,让后将图片路径上传到数据库内保存,并且我的行数不固定
listfile.jsp页面如下: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE HTML> <html> <head> <title>下载文件显示页面</title> </head> <body> <c:forEach var="me" items="${fileNameMap}"> <c:url value="${pageContext.request.contextPath}/servlet/DownLoadServlet" var="downurl"> <c:param name="filename" value="${me.key}"></c:param> </c:url> ${me.value}下载
</c:forEach> </body> </html> 将 <c:forEach var="me" items="${fileNameMap}"> <c:url value="${pageContext.request.contextPath}/servlet/DownLoadServlet" var="downurl"> <c:param name="filename" value="${me.key}"></c:param> </c:url> ${me.value}下载
</c:forEach>修改成类似<form action="${pageContext.request.contextPath}/servlet/UploadHandleServlet" enctype="multipart/form-data" method="post"> <input type="submit" value="下载">的类型,点击<input type="submit" value="下载">按钮,要跳转到用于处理文件下载的Servlet,DownLoadServlet,即${pageContext.request.contextPath}/servlet/DownLoadServlet,要完整代码
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
listfile.jsp页面如下: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE HTML> <html> <head> <title>下载文件显示页面</title> </head> <body> <c:forEach var="me" items="${fileNameMap}"> <c:url value="${pageContext.request.contextPath}/servlet/DownLoadServlet" var="downurl"> <c:param name="filename" value="${me.key}"></c:param> </c:url> ${me.value}下载
</c:forEach> </body> </html> 将 <c:forEach var="me" items="${fileNameMap}"> <c:url value="${pageContext.request.contextPath}/servlet/DownLoadServlet" var="downurl"> <c:param name="filename" value="${me.key}"></c:param> </c:url> ${me.value}下载
</c:forEach>修改成类似<form action="${pageContext.request.contextPath}/servlet/UploadHandleServlet" enctype="multipart/form-data" method="post"> <input type="submit" value="下载">的类型,点击<input type="submit" value="下载">按钮,要跳转到用于处理文件下载的Servlet,DownLoadServlet,即${pageContext.request.contextPath}/servlet/DownLoadServlet,要完整代码
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)