在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. MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作(转载)

    本文转载自:http://www.cnblogs.com/jpf-java/p/6013540.html 上一篇博文MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybati ...

  2. c# TimeSpan

    转自:http://blog.163.com/y_p_xu/blog/static/17085710220116472030543/ /// <summary>        /// 将时 ...

  3. erlang调试之JCL

    Job control mode (JCL), in which jobs can be started, stopped, detached or connected. Only the curre ...

  4. vue.js 学习笔记

    /*属性*/ 标签内的属性都用 :attr="xxx" 的形式 /*模板*/ {{ msg }} -> 绑定数据 {{ *msg }} -> 数据只绑定一次 {{{ m ...

  5. C# 中GUID生成格式的四种格式

    var uuid = Guid.NewGuid().ToString(); // 9af7f46a-ea52-4aa3-b8c3-9fd484c2af12 var uuidN = Guid.NewGu ...

  6. smarty中使用truncate出现乱码,用mb_substr解决

  7. error: RPC failed; result=22, HTTP code = 411

    git config http.postBuffer 524288000orgit config --system http.postBuffer 524288000  

  8. LeetCode Sum of Left Leaves

    原题链接在这里:https://leetcode.com/problems/sum-of-left-leaves/ 题目: Find the sum of all left leaves in a g ...

  9. varsh4.1 安装清除cache

    yum install automake autoconf ncurses-devel libxslt groff pkgconfig python-docutils readline-devel - ...

  10. 修复Magento SQLSTATE[23000]: Integrity constraint

    magneto在意外情况下报错Magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry,出现这个问题最 ...