以下代码在 Chrome 中运行良好,但在 IE9 中失败 - 在processFiles()
我们检索选定文件e.target.files
时null
<!DOCTYPE html>
<html>
<header>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
</header>
<body>
<input type="file" id="uploader"/>
<script>
var uploader = document.getElementById ("uploader");
if (uploader.addEventListener) { // all browsers except IE before version 9
uploader.addEventListener ("change", processFiles, false);
}
else {
if (uploader.attachEvent) { // IE before version 9
uploader.attachEvent ("change", processFiles);
}
}
function processFiles(e)
{
var files = e.target.files || e.dataTransfer.files;
for (var i = 0 ; i < files.length ; i ++)
{
window.console && console.log && console.log(files[i].name);
}
}
</script>
<body>
有任何想法吗?