input file 按钮美化

按钮美化

< span class= "upload" >
      < input type= "button" class= "upload-btn" value= "上传图片" />
      < span class= "upload-tip" ></ span >
      < input type= "file" class= "upload-input-file" name= "photo" />
</ span >

css:

/*input file 美化*/
.upload{ position: relative; display: inline-block; height: 33px; line-height: 33px; overflow: hidden; vertical-align: middle; cursor: pointer;}
.upload .upload-input-file{ width: 100%; position: absolute; right: 0; top: 0; /* font-size:100px;*/ opacity: 0; filter: alpha(opacity= 0); cursor: pointer;}
.upload .upload-btn{ max-width: 150px; overflow: hidden; min-width: 100px; outline: none; border: 0; height: 33px; line-height: 33px; color: #fff; background: #19a3fe; cursor: pointer; border-radius: 3px;}
.upload .upload-url { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; border-radius: 2px;
border: solid 1px #ddd; width: 200px; height: 30px; -webkit-line-height: 1; line-height: 30px \9; -ms-line-height: 30px; text-indent: 3px;}
.upload .upload-tip { cursor: pointer;; overflow: hidden; display: none; background-color: #19a3fe; padding: 2px 10px; color: #fefefe; font-size: 12px !important; border-radius: 3px;}


js:

//美化input file
$( ".upload .upload-input-file"). change( function () {
if ( $( this). parent(). html(). indexOf( "class= \" upload-url \" ") != - 1) {
var fileUrl = $( this). val();
$( this). parent(). children( ".upload-url"). val( fileUrl);
}
else {
var fileUrl = $( this). val();
var urlArr = fileUrl. split( " \\ ");
var getName = urlArr[ urlArr. length - 1]; //截取路径并获取文件的名字
// $(this).parent().children(".upload-tip").text(getName).fadeIn("slow");//在按钮外显示文件名
$( this). parent(). children( ".upload-btn"). val( getName); //按钮上变成文件名称
}
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值