input file文件上传CSS模拟为 选择 加 上传 两个按钮

原理就是把input type=file隐藏到下一层,用一个input type=txt覆盖到上一层。


CSS部分:

<style type="text/css">
.file-box{
position:relative;
width:100%;
}
.ftxt{
  width: 48%;
  display: inline-block;
  height: 32px;
  cursor: pointer;
  line-height: 32px;
  color: #e4e7e9;
  text-indent: 10px;
  border: 1px solid #e4e7e9;
  border-radius: 4px;
}
.ftxt:hover{
	border: 1px solid #1ab394;
 	color: #1ab394;
}
.ffile{
position:absolute; 
top:0;
left:0; 
height:32px; 
filter:alpha(opacity:0);
opacity: 0;
width: 48%;
}
</style>

HTML+JS部分:

<form action="" method="post" class="file-box">
	<input type='text' name='textfield' id='textfield' class='ftxt' value="请选择需要上传的" />  
	<input type='button' class='btn btn-block btn-primary' value='选择文件' οnclick="document.getElementById('fileField').click()" />
	<input type="file" name="fileField" class="ffile" id="fileField" size="28" οnchange="document.getElementById('textfield').value=this.value" οnmοuseοver="document.getElementById('textfield').style.color='#1ab394';document.getElementById('textfield').style.borderColor='#1ab394'" οnmοuseοut="document.getElementById('textfield').style.color='#e4e7e9';document.getElementById('textfield').style.borderColor='#e4e7e9'" />
	<input type="submit" name="submit" class="btn btn-block btn-success" value=" 导 入 " style="margin-left: 60%;" />
</form>


另外记录一个判断导入EXCEL文件的方法:

//判断导入Excel文件
function importExc(){
	var filePath = document.getElementById("excelPath").value;
	var fileType = "";
			
	if(filePath == ""){
		alert("请选择所要导入的文件!");
		return false;
	}else if(filePath.indexOf(".") < 0){
		alert("所要导入的文件格式不正确,请重新选择!");
		return false;
	}else{
		fileType = filePath.substring(filePath.lastIndexOf("."));
		if(".xls" != fileType && ".xlsx" != fileType){
			alert("所要导入的文件格式不正确,请重新选择!");
			return false;
		}else{
					
			//交给后台程序处理并提醒导入成功与否...	
					
	<span style="white-space:pre">	</span>}		
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值