空的输入类型文件在IE中不起作用 [英] Empty input type file doesn't work in IE

查看:74
本文介绍了空的输入类型文件在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这个简单的javascript代码:

I wrote this simple javascript code:

$("input[type='file']").attr("value", "");

它可以在Firefox和Chrome中使用,但不能在IE中使用(我在IE9中尝试过)

It works in Firefox and Chrome but not in IE (I tried in IE9)

清空输入类型文件值的好方法是什么?

What's the good approach to empty the input type file value ?

谢谢

推荐答案

输入类型=文件有一些限制

There are some restriction on input type = file

您可以阅读这似乎可以在IE8,IE9中使用

This seems to be working in IE8, IE9

$("input[type='file']").replaceWith($("input[type='file']").clone(true));

要在IE8中进行测试,我将开发人员工具中的兼容模式更改为IE8

To test in IE8 I changed the compatibility mode in developer tool to IE8

对于许多IE骇客,我认为这会更好

As for many IE hacks I think this is better

    if($.browser.msie){
        $("input[type='file']").replaceWith($("input[type='file']").clone(true));
    } else {
        $("input[type='file']").val('');
    }

这篇关于空的输入类型文件在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆