ie8及其以下版本兼容性问题之input file隐藏上传文件
文件上传时,默认的file标签很难看,而且每个浏览器下都有很大差距。因此我们基本都把真正的file标签给隐藏,然后创建一个标签来替代它。但是由于IE出于安全方面的考虑上传文件时必须点击file的浏览按钮选择文件才可以把文件上传上去。此时我们可以将file input透明化, 遮罩在自定义的button input 上面。这样用户看到的是我们自定义button的外观而实际上点击的还是file标签。
这样一来我们自定义的按钮存在又能真正点击到file标签,IE下就可以正常上传文件了。
示例:
//html
<div class="modifyInfo_upload pr">
<span>上传头像</span>
<input type="file" name="portrait" id="upLoadPortrait" value="">
</div>
//css
.modifyInfo_upload{
height: 30px;
text-align: center;
margin-bottom: 29px;
}
.modifyInfo_upload span{
height: 30px;
line-height: 30px;
color: #1db69a;
cursor: pointer;
}
.modifyInfo_upload input{
width: 58px;
height: 20px;
overflow: hidden;
opacity: 0;
-ms-filter:"alpha(opacity=0)";
position: absolute;
top: 4px;
left: 0;
right: 0;
margin: 0 auto;
cursor: pointer;
}
//js
var portraitPath;
$("#upLoadPortrait").on('change',function(event){
if($(this).val() != ''){
var strExtension = $(this).val().substr($(this).val().lastIndexOf('.') + 1);
if (strExtension != 'jpg' && strExtension != 'gif' && strExtension != 'png' && strExtension != 'bmp') {
alert("请选择图片文件!");
}else{
portraitPath = $(this).val();
console.log(portraitPath);
$('.modifyInfo_portrait img').attr('src',portraitPath);
}
}
});
参考链接:IE input file隐藏不能上传文件解决方法
ie8及其以下版本兼容性问题之input file隐藏上传文件的更多相关文章
- html input file accept 上传文件类型限制格式 MIME 类型列表
例: <input type="file" accept="application/vnd.openxmlformats-officedocument.spread ...
- input file限制上传文件类型
http://www.cnblogs.com/haocool/p/3431181.html http://www.haorooms.com/post/input_file_leixing http:/ ...
- input file 图片上传
使用第三方:jquery.ajaxfileupload.jsinput中的name根据后端来定 <form method="post" enctype="multi ...
- input type file onchange上传文件的过程中,遇到同一个文件二次上传无效的问题。
不要采用删除当前input[type=file]这个节点,然后再重新创建dom这种方案,这样是不合理的.解释如下:input[type=file]使用的是onchange去做,onchange监听的为 ...
- input[type='file']获取上传文件路径案例
最近在项目时,需要获取用户的上传文件的路径,便写了一个demo: <body> <input type="file" name="" valu ...
- Java&Selenium借助AutoIt 实现非Input类型自动化上传文件
通常情况下实现自动化上传文件,都是通过sendKeys函数直接将文件全路径传给页面空间就能完成,然而这种情况只能对Input类型的控件有效,对于非Input类型的控件可以借助AutoIt来完成 下载地 ...
- input type file onchange上传文件的过程中,同一个文件二次上传无效的问题。
不要采用删除当前input[type=file]这个节点,然后再重新创建dom这种方案,这样是不合理的.解释如下:input[type=file]使用的是onchange去做,onchange监听的为 ...
- input type='file'限制上传文件类型
前端与后台数据进行对接时,就避免不了要使用ajax进行http请求,常用的请求就两个post与get:然而常见的post请求的需求是文件上传,可能我一说到文件上传大家都觉得so easy啊,没什么嘛 ...
- form input file 图片上传360IE兼容问题
<form action="" class="form-box" class="form_box" enctype="mul ...
随机推荐
- webstorm下ES6转ES5
ECMAScript 6是JavaScript语言的下一代标准,已经在2015年6月正式发布了.Mozilla公司将在这个标准的基础上,推出JavaScript 2.0. ES6的目标,是使得Java ...
- 手机访问pc版网站自动跳转为手机版页面
1.PC版首页</head>标签前加上以下脚本 <script src="/tools/browser_redirect.ashx"></script ...
- noip模拟赛 三部曲
分析:子树上操作,要用到线段树+dfs序,关键就是子树内k还要增加,这个就不是很好办.可以求出在根节点+0后每个点会加多少,记为d[i],如果要对点x进行A操作,实际上只需要对子树加k - d[i]再 ...
- F - True Liars 带权并查集
After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ...
- spring boot.定时任务问题记录(TaskScheduler/ScheduledExecutorService异常)
一.背景 spring boot的定时任务非常简单,只需要在启动类中加上@EnableScheduling注解,然后在对应的方法上配置@Scheduled就可以了,系统会自动处理并按照Schedule ...
- Android中@+id和@id的差别
Android中的组件须要用一个int类型的值来表示.这个值也就是组件标签中的id属性值. id属性仅仅能接受资源类型的值,也就是必须以@开头的值,比如,@id/abc.@+id/xyz等. 假设在 ...
- IntelliJ IDEA 在左右两侧出现Project、Maven Project等导航按钮
IntelliJ IDEA 在左右两侧出现Project.Maven Project等导航按钮 选中 View > Tool Buttons 可以查看Project.Maven Project等 ...
- 3.0 - remote access 基础知识
RA概述: remote access: 广域网的远程连接,按L1分类: 1:通过电路交换网络实现的专线:(circuit switching) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
- Unity3D中的Coroutine具体解释
本文太乱,推荐frankjfwang的:全面解析Coroutine技术 Unity中的coroutine是通过yield expression;来实现的.官方脚本中到处会看到这种代码. 疑问: yie ...
- [Node.js] Setup Local Configuration with Node.js Applications
Github To stop having to change configuration settings in production code and to stop secure informa ...