运用css 美化 上传控件 file 技巧

效果图:


主要的css样式:

.upload_file{   /*上传文本框的样式*/
	background: url(../images/upload_bg.jpg) no-repeat;
	width: 317px;
	height: 18px;
	border-width:0px;
	margin: 5px;
	padding:6px;
	line-height:20px;
	color:#999;
	
}

.upload_button{ /*上传文件的的浏览按钮*/
	background:url(../images/upload_button.jpg) no-repeat;
	width:91px;
	height:29px;
	border-width:0px;
	text-align:center;
	color:#107F66;}
页面的html 代码:  <!--此处为真正的上传控件-->
<input id="file" type="file" value="" onchange="changfileText()" style="display:none;" /> 

<!--虚拟的上传输入框-->
<input id="fileText" type="text" class="upload_file" style="float:left;" size="45" 
            readonly="readonly" value="请选择上传到图片" onclick="uploadFile()"/> 
<!--虚拟的上传浏览按钮-->
<input class="upload_button" style="float:left; margin:5px 0;  _display: inline;" type="button"
             value="浏览" onclick="uploadFile()" />


js 实现代码:

function uploadFile(){ //相当于file文件点击
     document.getElementById("file").click();
      }         
function changfileText(){
    //将真正的file的value值赋予虚拟的文本框中供前台显示
    document.getElementById("fileText").value=document.getElementById("file").value;
      }


转载于:https://my.oschina.net/haopeng/blog/91077

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值