input标签file的value属性IE兼容性问题
在IE中input标签file的value属性是只读的,不能通过js来改变,如下代码在IE中就是无效的:
var input = document.getElementById('file'); input.value = '';
所以当在file中上传了同一张图片时,是不会触发file的change事件的。
但在其他浏览器里就可以轻易的使用js改变value值,使上传同一图片时触发change事件。
为了解决这个问题就要在每次图片上传完成后删除掉这个input再重新生成一个input插入到DOM中,大概的代码如下:
resetFile = function(ele, form, name, str){ var parent = ele.parentNode; var input = $C('input'); input.type = 'file'; input.className = 'file'; input.name = str; input.id = str; parent.removeChild(ele); parent.appendChild(input); nodes[name] = input; Core.Events.addEvent(nodes[name],function(){ var imgvalue = ele.value; if(imgvalue != ''){ form.submit(); } },'change'); };
(此代码引用于blog7icp的blog7icp/jobs/bankcardbind.js)
注意:在生成新的input之后要重新绑定change事件,之前绑定的change事件已经跟随着被删除的input删除了。
input标签file的value属性IE兼容性问题的更多相关文章
- input标签file文件上传图片本地预览
<input type="file" name="img-up" id="img-up" value="" /&g ...
- input标签添加上disable属性在移动端(ios)字体颜色及边框颜色不兼容的解决办法。
手机一些兼容性问题: 1.苹果手机输入框input:disabled显示模糊问题 input:disabled, input[disabled]{ color: #5c5c5c; -webkit-te ...
- HTML5中input标签有用的新属性
HTML5对input增加了一些新标签,个人觉得比较常用有效的以下几个 placeholder=“请输入” 常见用于默认提示 autofocus 自动聚焦到当前输入框 maxlength=" ...
- type为number的<input>标签 type和size属性失效
html5中input的type属性增的可取值新增几种,对于不支持这几种新增值的浏览器会统一解析为text类型. Firefox.ie9不支持
- input标签元素,value属性取值问题,赋值
验证val:<input type="text" id="id" name="name" value="空值"&g ...
- input标签添加上disable属性在ios端字体颜色不兼容的问题
input[disabled],input:disabled,input.disabled{ color: #3e3e3e; -webkit-text-fill-color: #3e3e3e; -we ...
- input标签添加上disable属性在移动端字体颜色不兼容的解决办法。
input[disabled],input:disabled,input.disabled{ color: #999; -webkit-text-fill-color:#999; -webkit-op ...
- html5中form表单新增属性以及改良的input标签元素的种类
在HTML5中,表单新增了一些属性,input标签也有了更多的type类型,有些实现了js才能实现的特效,但目前有些浏览器不能全部支持.下面是一些h5在表单和input标签上的一些改动. <!D ...
- input标签的accept属性、JQuery绑定keyDown事件
一. input标签的accept属性 当我们上传文件或者注册上传头像时,我们可以一般都是使用: <input type="file" id="my_file&qu ...
随机推荐
- iOS9 适配(杂七杂八)
1.iOS9 以后,table cell 在旋转的时候会自动调整视图内容的布局,设置以下的属性,课禁止该行为. if (runTimeOSVersion >= 9.0f) { _listTabl ...
- 极简Photoshop 教程
本文通过创建一个iPhone应用的启动界面来介绍常用的Photoshop 用法. 1,以下参数创建一个新图像 宽度:1242像素,高度:22208像素,分辨率:401,背景内容:透明,其它默认 2,建 ...
- linux 查找文件的命令
http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html
- Tomcat-问题解决
1,两种方法解决tomcat的 Failed to initialize end point associated with ProtocolHandler ["http-apr-8080& ...
- js的高级知识---词法分析
词法分析 词法分析方法: js运行前有一个类似编译的过程即词法分析,词法分析主要有三个步骤: 分析参数 再分析变量的声明 分析函数说明 具体步骤如下: 函数在运行的瞬间,生成一个活动对象(Active ...
- C语言的概述--学习c的第二天
以下是整理的知识点: #include <stdio.h>/* 引入stdio.h文件c的标准函数库 */ int main(void)/* 定义一个函数main(),int定义函数返回的 ...
- CAS学习笔记(一)
近期做单点登录,看了一些CAS资料,做下总结 一.cas简介 全名:Central Authentication Service 特点: 1.开源的.多协议的 SSO 解决方案: Protocols ...
- SQLServer2008R2企业版密匙
SQLServer2008R2企业版密匙: R88PF-GMCFT-KM2KR-4R7GB-43K4B
- Hadoop:部署Hadoop Single Node
一.环境准备 1.系统环境 CentOS 7 2.软件环境 OpenJDK # 查询可安装的OpenJDK软件包[root@server1] yum search java | grep jdk... ...
- Openbox简单支持平铺
使用和gnome shell同样的热键定义 rc.xml中 <keybind key="W-Up"> <action name="Maximize&qu ...