在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兼容性问题的更多相关文章

  1. input标签file文件上传图片本地预览

    <input type="file" name="img-up" id="img-up" value="" /&g ...

  2. input标签添加上disable属性在移动端(ios)字体颜色及边框颜色不兼容的解决办法。

    手机一些兼容性问题: 1.苹果手机输入框input:disabled显示模糊问题 input:disabled, input[disabled]{ color: #5c5c5c; -webkit-te ...

  3. HTML5中input标签有用的新属性

    HTML5对input增加了一些新标签,个人觉得比较常用有效的以下几个 placeholder=“请输入” 常见用于默认提示 autofocus 自动聚焦到当前输入框 maxlength=" ...

  4. type为number的<input>标签 type和size属性失效

    html5中input的type属性增的可取值新增几种,对于不支持这几种新增值的浏览器会统一解析为text类型. Firefox.ie9不支持

  5. input标签元素,value属性取值问题,赋值

    验证val:<input type="text" id="id" name="name" value="空值"&g ...

  6. input标签添加上disable属性在ios端字体颜色不兼容的问题

    input[disabled],input:disabled,input.disabled{ color: #3e3e3e; -webkit-text-fill-color: #3e3e3e; -we ...

  7. input标签添加上disable属性在移动端字体颜色不兼容的解决办法。

    input[disabled],input:disabled,input.disabled{ color: #999; -webkit-text-fill-color:#999; -webkit-op ...

  8. html5中form表单新增属性以及改良的input标签元素的种类

    在HTML5中,表单新增了一些属性,input标签也有了更多的type类型,有些实现了js才能实现的特效,但目前有些浏览器不能全部支持.下面是一些h5在表单和input标签上的一些改动. <!D ...

  9. input标签的accept属性、JQuery绑定keyDown事件

    一. input标签的accept属性 当我们上传文件或者注册上传头像时,我们可以一般都是使用: <input type="file" id="my_file&qu ...

随机推荐

  1. 贪吃蛇的java代码分析(二)

    代码剖析 贪吃蛇是一款十分经典的小游戏,对初入coding的朋友来说,拿贪吃蛇这样一个案例来练手十分合适,并不高的难度和成功后的成就感都是学习所必须的.下面我将依照我当时的思路,来逐步分析实现的整个过 ...

  2. ActiveMQ简介

    ActiveMQ 1.ActiveMQ是什么ActiveMQ是Apache推出的一款开源的完全支持JMS1.1和J2EE1.4规范的JMS Provider实现的消息中间件(Message Orien ...

  3. Autorelease自动释放池的使用

    Autorelease自动释放池的使用 使用ARC开发,只是在编译时,编译器会根据代码结构自动添加了retain.release和autorelease. MRC内存管理原则:谁申请,谁释放 遇到al ...

  4. ios - runtime运行时应用---交换方法

    runtime运行时用法之一 --- 交换类的方法,此处简单写了把系统的UIView的setBackgroundColor的方法换成了自定义的pb_setBackgroundColor 首先创建UIV ...

  5. Programming paradigms

    https://en.wikipedia.org/wiki/Aspect-oriented_programming Action Agent-oriented Array-oriented Autom ...

  6. Prototype based langue LUA

    Prototype-based programming https://en.wikipedia.org/wiki/Prototype-based_programming Prototype-base ...

  7. .NET中Redis安装部署及使用方法简介附->开源Redis操作辅助类

    Redis是一个用的比较广泛的Key/Value的内存数据库,新浪微博.Github.StackOverflow 等大型应用中都用其作为缓存,Redis的官网为http://redis.io/. Re ...

  8. c++防止客户端多开巧妙代码

    在读OBS源码时看到一个比较有意思的关于防止用户多开程序的写法,简单有效,记录下 //make sure only one instance of the application can be ope ...

  9. Android四大核心组件之BroadCastReceiver

    实验内容 实现BroadCast发送和接受 通过BroadCast传递信息 动态注册和注销BroadCast 实验要求 实现BroadCast发送和接受 通过BroadCast传递信息 动态注册和注销 ...

  10. ubuntu安装node.js+express+mongodb

    输入以下命令安装: sudo apt-get install nodejs 安装完成后,终端输入nodejs,就能进入node命令啦: 但是正常下应该是输入node进入命令而不是nodejs: 在Ub ...