最近在公司做项目时需要用到html的上传文件控件,但发现原生的上传文件控件<input type="file" />在IE、Chrome浏览器的显示效果相差很大,为了统一样式,我参考了网上的许多方法,下面给出我自己的代码实现(实际上就是在原生的input file上面加个外壳,再添加一些样式,让它看上去不像原生的这么丑)

html部分

<div class="upload-box">
<div class="input">
<input type="file" id="input" size="45"/> <!--原生的file-->
</div>
<div class="upload">
<div class="upload-choose">选择文件</div>
<div class="upload-info"></div>
</div>
</div>

css部分

 .upload-box {
position: relative;
} .input {
height: 30px;
position: absolute;
top: 0px;
left: 0px;
} input[type="file"] {
border: 1px solid red;
width: 480px;
opacity:;
} input[type="submit"] {
width: 100px;
height: 30px;
background: #ddd;
border: none;
} .upload-choose {
width: 80px;
height: 30px;
background: #eee;
float: left;
text-align: center;
line-height: 30px;
font-family: "Microsoft YaHei";
font-size: 14px;
font-weight: bold;
} .upload-info {
width: 400px;
border: 1px solid #eee;
height: 28px;
line-height: 28px;
float: left;
padding-left: 5px;
overflow: hidden;
}

js部分

 $(function(){
$("#input").change(function(){
var filename_split = $(this).val().split("\\");
var filename = filename_split[filename_split.length - 1];
$(".upload-info").text(filename);
});
});

这样基本上可以实现和原生上传控件相同的效果

兼容IE浏览器样式的html上传文件控件的更多相关文章

  1. html+css上传文件控件美化

    html上传美化: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  2. jquery上传文件控件Uploadify

    基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件. 要求使用jquery1.4或以上版本,flash player 9.0.24以上. 有两个 ...

  3. jQuery上传文件控件Uploadify使用

    Uploadify是JQuery的一个上传插件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件等. 首先应下载jQuery和uploadify插件 jQuery下载地址:h ...

  4. asp.net 页面上传文件控件后台代码Request.Files获取不到

    今天开发中遇到页面文件上传控件选择了文件,而后台Request.Files.Count取值为0,之前开发中遇到过几次,老是忘掉,今天记下来. html: <input type="fi ...

  5. ASP.NE 上传文件控件

    protected void Button1_Click(object sender, EventArgs e) { //if (Request["id"]==null & ...

  6. 用JS怎么判断上传文件控件是否未选择文件

    页面代码: <form name="form1" action="uploadPosdetailFile.html" method="post& ...

  7. JS兼容各个浏览器的本地图片上传即时预览效果

    JS兼容各个浏览器的本地图片上传即时预览效果 很早以前 在工作曾经碰到这么一个需求,当时也是纠结了很久,也是google了很久,没有碰到合适的demo,今天特意研究了下这方面的的问题,所以也就做了个简 ...

  8. 兼容各浏览器的js判断上传文件大小

    由于项目需要,在网上找了一个JS判断上传文件大小的程序,经测试兼容IE6-,Firefox10,Opera11.,safari5.,chrome17 <!DOCTYPE html> < ...

  9. ubuntu 搭建ftp服务器,可以通过浏览器访问,filezilla上传文件等功能

    搭建ftp服务器 1:首先,更新软件源,保证源是最新的,这样有利于下面在线通过apt-get install命令安装ftp. 2:使用sudo apt-get install vsftp命令安装vsf ...

随机推荐

  1. 【数据表格】datatable+SpringMVC+Spring Data JPA

    初步实现 $("#userTable").dataTable({ "processing": true, "serverSide": tru ...

  2. 【Thymeleaf】常用属性

    参考链接 Thymeleaf 常用属性

  3. python基础-----字符编码

    1.ASCII ASCII(American Standard Code for Information Interchange,美国标准信息交换代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现 ...

  4. Java 遍历List中删除的解决方法

  5. android 组建添加透明度

    给TextView添加透明度,起初用的方法是android:alpha = "0.3"  添加后,文字显示也有点透明发虚,后来改成设置background,然后 backgroun ...

  6. 手写代码注意点--java.lang.Math 相关

    1-如果用到了Math的函数,需要手动写上: import java.lang.Math; 2-求x的y次方,用的是Math.pow(x,y); 注意,返回值是double!!! 不是int, 如果需 ...

  7. [Docker]Docker拉取,上传镜像到Harbor仓库

    需求 因为项目的需求,需要制作一个基于tomcat的镜像.那么前提就是,需要有tomcat的基础镜像. 怎么做 我的思路跑偏了,本来以为是需要将tomcat下载下来,然后通过docker命令,让它成为 ...

  8. 【python网络爬虫】之requests相关模块

    python网络爬虫的学习第一步 [python网络爬虫]之0 爬虫与反扒 [python网络爬虫]之一 简单介绍 [python网络爬虫]之二 python uillib库 [python网络爬虫] ...

  9. Linux中目录proc/net/dev详解【转】

    转自:https://blog.csdn.net/yzy1103203312/article/details/77848192 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...

  10. Epoll模型【转】

    转自:https://www.cnblogs.com/tianhangzhang/p/5295972.html 相比于select,epoll最大的好处在于它不会随着监听fd数目的增长而降低效率.因为 ...