修改file按钮的样式

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
 <head>
  <title>添加附件</title>
 </head>
<script type="text/javascript" src="jquery-1.8.0.js"></script>
  <script type="text/javascript">
   function fclick(obj){
	  style.posTop=event.srcElement.offsetTop 
	  style.posLeft=event.x-offsetWidth/2
   }
   $(function(){
		$("#addFile").click(function(){
			var br = $("<br>");
			var input1 = $("<input id='inputrecievedocument' type='text'/>");
			var input2 = $("<input type='button' style='margin-left:5px;background-color:blue' id='btnrecievedocument' οnmοuseοver='fclick(t_file)' value='浏览'/>");
			var input3 = $("<input name='upfile' type='file' style='position:absolute;filter:alpha(opacity=0);width:70px;' id='t_file' οnchange='inputrecievedocument.value=this.value' hidefocus/>");
			var button = $("<input type='button' value='删除' style='margin-left:5px;background-color:blue'/>");
			$("#file").append(br).append(input1).append(input3).append(input2).append(button);
			button.click(function() {
				br.remove();
				input1.remove();
				input2.remove();
				input3.remove();
				button.remove();
			});
		
		});
		
   });
  </script>
 <body class="body">
  <form method="post" action="" enctype="multipart/form-data">
  <input type="button" value="添加附件" class="btn_fujian" id="addFile" style="margin-left:20px;margin-top:2px;"/>
   <div id="file"></div>
 
  </form>
 </body>
</html>


IE9中运行如下:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
修改input type=file样式,可以使用CSS来实现。但是由于input type=file的设计,只有很少的CSS属性可以应用于它。所以,我们需要使用一些技巧才能改变它的外观。以下是一些实现方法: 方法一:使用label元素代替input元素,并使用CSS样式来美化label元素。 HTML代码: ``` <label for="file-upload" class="custom-file-upload"> <i class="fa fa-cloud-upload"></i>选择文件 </label> <input id="file-upload" type="file"/> ``` CSS代码: ``` .custom-file-upload { display: inline-block; padding: 6px 12px; cursor: pointer; border: 1px solid #ccc; border-radius: 4px; } .custom-file-upload:hover { background-color: #f5f5f5; } .custom-file-upload i { margin-right: 5px; } ``` 方法二:使用伪元素和背景图片来美化input元素。 HTML代码: ``` <input type="file" class="custom-file-input"/> <label class="custom-file-label" for="custom-file-input">选择文件</label> ``` CSS代码: ``` .custom-file-input { position: absolute; left: -9999px; } .custom-file-label { display: inline-block; padding: 6px 12px; cursor: pointer; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; font-weight: normal; background-image: url('file-upload.png'); background-repeat: no-repeat; background-position: center; background-size: 16px; padding-left: 24px; } .custom-file-label:hover { background-color: #f5f5f5; } ``` 其中,file-upload.png是一个上传图标的图片。 以上两种方法都可以实现美化input type=file的效果。您可以根据自己的需求选择其中一种方法进行使用。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值