以上是默认的

<input type="file" >

但是丑爆了啊同志们~~长久以来都是调用大神的代码,今天我也小试牛刀,做出了如下效果:

这样还是能接受的样子啦~

LOOK!

html文件:

<div class="fileBox">
<div class="fileName"></div>
<button class="fileButton">选择文件</button>
<input type="file" class="file1">
</div>
<div class="fileBox">
<div class="fileName"></div>
<button class="fileButton">选择文件</button>
<input type="file" class="file2">
</div>

css文件:

        .fileBox{
position: relative;
display: inline-block;
}
.fileButton{
display: inline-block;
width: 80px;
height: 34px;
line-height: 34px;
background: #FFA837;
border-radius: 0px 4px 4px 0px;
text-align: center;
color: #fff;
vertical-align: top;
}
.file1,.file2{
width: 80px;
height: 34px;
position: absolute;
top: 0px;
right: 0px;
opacity:;
filter:Alpha(opacity=0); /*透明度兼容IE8*/
vertical-align: top;
}
.fileName{
display: inline-block;
width: 150px;
height: 34px;
line-height: 34px;
padding:0px 5px;
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
border: 1px solid #eee;
vertical-align: top;
float: left;
}

js文件:

function upFile(fileX){
var path;
var fileName;
var file=fileX;
var fileFrame=fileX.parent(".fileBox").children(".fileName");
path=file.val();

//path为获取的<input type="file">的文件名或文件路径
//火狐获取的是文件名,所以pos=-1,chrome和IE获取的是文件路径

if(path!=''){
var pos1 = path.lastIndexOf('/');
var pos2 = path.lastIndexOf('\\');
var pos = Math.max(pos1, pos2)
if( pos<0 ){
fileName =path;
fileFrame.text(fileName);
fileFrame.attr("title",fileName);
}
else{
fileName=path.substring(pos+1);//截取从pos+1索引到末尾
fileFrame.text(fileName);
fileFrame.attr("title",fileName);
}
}
}

调用:

$(".file1").change(function(){
upFile($(this));
});
$(".file2").change(function(){
upFile($(this));
});

以后只要调用upFile()就可以啦~是不是超级棒~超级美~

兼容:IE8+,firefox,chrome~

过来为菜鸟点赞吧!

修改默认input(file)的样式的更多相关文章

  1. JS 更改表单的提交时间和Input file的样式

    JS转换时间 function renderTime(data) { var da = eval('new ' + data.replace('/', '', 'g').replace('/', '' ...

  2. 【JS】 伪主动触发input:file的click事件

    大家用到input:file标签时,对于input:file的样式难看的处理方法一般有2种: 采用透明化input:file标签的方法,上面放的input:file标签,下面放的是其他标签,实际点击的 ...

  3. input file样式修改,图片预览删除功能

    本篇对input file进行了修改,改成自己需要的样式,类似验证身份上传身份证图片的功能. 效果图如下: 这里主要展示上传预览图片功能,对于删除功能的html及css写的比较粗糙,对于想要精细表现这 ...

  4. input:file样式怎样修改

    问题描述: 我需要点击input:file来修改img中的图片,但是input:file样式太丑 解决办法: 给file设置透明度为0,让用户看不见他 创建新的button按钮 修改button按钮样 ...

  5. input(file)样式修改及上传文件名显示

    实现思路: a标签包裹input元素 设置a标签为上传按钮的样式,相对定位 设置input为透明,绝对定位,覆盖到a上面 效果:看到的按钮是a的样式,点击时实际是点击input元素.样式和功能都具备 ...

  6. input file样式美化

    默认样式: <input type="file" /> 美化样式时: 将其设置为透明,设置宽高覆盖到需要用的地方,宽100%,高100% 可以用到定位 .box{ po ...

  7. Bootstrap中关于input里file的样式更改

    给input里file类型加button样式 1.在Bootstrap中input里的file类型样式很不美观,一个按钮加一段文字,还会随浏览器的不同呈现不同的样式,所以开发的时候可以将file的样式 ...

  8. input file 文件上传标签的样式美化

    input file 文件上传标签的样式美化 将<input type="file">的透明度设置为0: <input type="file" ...

  9. 巧妙利用label标签实现input file上传文件自定义样式

    提到上传文件,一般会想到用input file属性来实现,简单便捷,一行代码即可    但input file原生提供的默认样式大多情况下都不符合需求,且在不同浏览器上呈现的样式也不尽相同   我们往 ...

随机推荐

  1. 转载 - KMP算法祥解

    出处:http://www.cppblog.com/oosky/archive/2006/07/06/9486.html KMP字符串模式匹配详解 来自CSDN     A_B_C_ABC 网友 KM ...

  2. A - 敌兵布阵(HDU 1166)

    A - 敌兵布阵 HDU - 1166 思路:线段树单点修改+区间查询. #include<cstdio> #include<cstring> #include<iost ...

  3. UVA Jin Ge Jin Qu hao 12563

    Jin Ge Jin Qu hao (If you smiled when you see the title, this problem is for you ^_^) For those who ...

  4. 【网络协议】ICMP协议、Ping、Traceroute

        ICMP协议 ICMP常常被觉得是IP层的一个组成部分,它是网络层的一个协议.它传递差错报文以及其它须要注意的信息.ICMP报文通常被IP层或更高层(TCP.UDP等)使用,它是在IP数据报内 ...

  5. win7_64

    转到YLMF DOS工具,输入ghost然后回车 enter后 选择options进入

  6. 齐头并进完成任务——Java多线程(一)

    多线程(Multithread)指的是在单个进程中同时运行多个不同的线程,执行不同的任务.多线程意味着一个程序的多行语句块并发执行. 一.实现多线程 1.通过继承Thread类实现多线程. Threa ...

  7. badboy提示脚本错误解决方法

    1.输入URL,提示脚本错误 解决办法:打开IE浏览器,工具->internet选项->高级,如图所示去掉禁用脚本调试 2.badboy内置浏览器,提示脚本错误解决办法 解决办法:badb ...

  8. Camera-hal参数调整

    路径: vendor/mediatek/proproetary/custom/mt6735/hal/D1/imgsensor/对应的SENSOR目录 .../D1/flashlight/flash_t ...

  9. Hdu-6252 2017CCPC-Final J.Subway Chasing 差分约束

    题面 题意:有2个人,都去坐地铁,但是他们相差了X分钟,但是他们也一直在通讯,于是你就知道,你在AB站点中间的时候,他在CD中间,(B一定等于A+1或者A,同理D也是),问你每2个站之间需要的时间的一 ...

  10. 负载均衡获得真实源IP的6种方法

    除了X-FORWARD-FOR,负载均衡中获得真实源IP的方法还有很多种. 本文抛砖引玉,主要介绍获得真实源IP的多种方法,而不是具体配置. 负载均衡获得真实IP的方法有很多种,将形成专题文章. 本文 ...