我写了这个简单的javascript代码:
$("input[type='file']").attr("value", "");
Run Code Online (Sandbox Code Playgroud)
它适用于Firefox和Chrome,但不适用于IE(我在IE9中试过)
清空输入类型文件值的好方法是什么?
谢谢
mpr*_*hat 10
input type = file有一些限制
你可以在这里阅读
这似乎适用于IE8,IE9
$("input[type='file']").replaceWith($("input[type='file']").clone(true));
Run Code Online (Sandbox Code Playgroud)
为了在IE8中进行测试,我将开发人员工具中的兼容模式更改为IE8
编辑:
至于许多IE黑客,我认为这更好
if($.browser.msie){
$("input[type='file']").replaceWith($("input[type='file']").clone(true));
} else {
$("input[type='file']").val('');
}
Run Code Online (Sandbox Code Playgroud)