IE8 - input (type="file") 获取文件

12

我在使用Internet Explorer(仅测试过版本8)中的输入框(type="file")时遇到了问题。

HTML

<input id="drop-file-files" class="drop-file-waiting" type="file">

JS(http://code.jquery.com/jquery-latest.min.js)

$('#drop-file-files').change(function(e){
    $.each(e.target.files, function(index, file){
        alert(file);
    });
});

这在Firefox、Chrome和Safari中运行得很完美,返回文件对象。但是,在IE中会因为e.target中的“files”未定义而报错。有人知道怎样用JavaScript获取到这个“files”吗?

编辑:文档MSDN input type=file - 仅适用于IE10的files属性

1个回答

14

Internet Explorer 8 不支持多个文件。已经在这里讨论过这个问题。你至少可以通过e.target.value获取文件名。


好的,我知道它不支持多个文件,但是我如何获取文件的信息呢? - Thyago Quintas
@ThyagoQuintas,e.originalEvent.dataTransfer.files[0] 对你可用吗? - Matthias
不,我选择文件后dataTransfer为空。 - Thyago Quintas
@ThyagoQuintas 抱歉,我搞混了。我更新了我的答案。 - Matthias
@Matthias 那么如何获取单个文件? - Prashant Pimpale

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接