<input type=“file“/> 修改默认样式无效

解决思路:<input type="file"/>修改默认样式无效,那就设置div的样式然后让该div触发<input type="file"/>的上传功能

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<style>
			#coverDiv {
				width: 100px;
				height: 45px;
                line-height:45px;
				background-color: red;
                font-size:16px;
                text-align:center;
                color:white;
                border-radius:5px;
			}
			#file {
				width: 200px;
				height: 50px;
				background-color: red;
			}
		</style>
	</head>
	<body>
		<div id="coverDiv">点击上传</div>
		<input type="file" id="file"/>
		
	</body>
</html>

 解决办法如下

效果:设置div的样式然后让该div触发<input type="file"/>的上传功能,返回值为上传文件/图片的名字

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<style>
			#coverDiv {
				width: 100px;
				height: 45px;
				line-height: 45px;
				background-color: red;
				font-size: 16px;
				text-align: center;
				color: white;
				border-radius: 5px;
			}
			#file {
				width: 200px;
				height: 50px;
				background-color: red;
			}
		</style>
	</head>
	<body>
		<div id="coverDiv">点击上传</div>
		<input type="file" id="file" style="display: none" multiple />
		<ul id="content"></ul>
	</body>
	<script>
		document.getElementById("coverDiv").onclick = function () {
			document.getElementById("file").click();
		};

		document.getElementById("file").onchange = function () {
			let lis = "";
			for (let a = 0; a < this.files.length; a++) {
				lis += `<li>${this.files[a].name}</li>`;
			}
			document.getElementById("content").innerHTML = lis;
		};
	</script>
</html>
<div class="table-container"> <table id="myTable"> <thead> <tr> <th contenteditable="true" ><input type="text" oninput="filterTable(1)" placeholder="aoiStep" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(2)" placeholder="defectType" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(3)" placeholder="layerCode" ></th> <th contenteditable="true" ><input type="text" oninput="filterTable(4)" placeholder="type"></th> <th contenteditable="true" ><input type="text" oninput="filterTable(5)" placeholder="dpet" ></th> <th contenteditable="true"><input type="text" oninput="filterTable(6)" placeholder="subcode" ></th> <th contenteditable="true" ><input type="text" placeholder="codeDescription" ></th> <th contenteditable="true" >image1</th> <th contenteditable="true" >image2</th> <th contenteditable="true">image3</th> <th contenteditable="true" >image4</th> <th contenteditable="true" >image5</th> <th contenteditable="true" ><input type="text" placeholder="determination_rule"></th> </tr> </thead> <tbody> <form action="unload.php" method="POST" enctype="multipart/form-data"> <tr> <td input type="text" name="aoi_step">3</td> <td input type="text" name="defect_type">Particle</td> <td input type="text" name="layer_code">ACT</td> <td input type="text" name="type">Particle</td> <td input type="text" name="dpet">ACT</td> <td input type="text" name="subcode">Particle</td> <td input type="text" name="code_description">ACT</td> <td> <input type="file" name="image1_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> <td> <input type="file" name="image2_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td> <input type="file" name="image3_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td> <input type="file" name="image4_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td> <input type="file" name="image5_path" onchange="previewImage(this);selectCell(this)" onclick="showPopup(this.src)" style="width: 100px; height: auto;"> </td> <td input type="text" name="determination_rule">Particle</td> <tr> <button type="submit">提交</button> </tr> </form> </tbody> </div> <script>修改后在我提娜佳图片是报错
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值