我需要加载一个文件来输入。 此代码适用于 chrome、opera 和 firefox,但不适用于 IE:
$("input:file").change(function ()
{
// Get a reference to the fileList
var files = !!this.files ? this.files : [];
// If no files were selected, or no FileReader support, return
if ( !files.length || !window.FileReader ) return;
// Only proceed if the selected file is an text
if ( /^text/.test( files[0].type ) )
{
var reader = new FileReader();
reader.readAsText( files[0] );
reader.onloadend = function()
{
restoreCSS(this.result);
}
}
}
在 IE 中 !!this.files
返回 false。感谢您的提前。
最佳答案
您使用的是哪个版本的 IE? FileReader
isn't supported in IE until version 10 .
正如@apsillers 评论的那样,有 another question asking about how to imitate FileReader
support in browsers that don't support it .我相信它们都需要某种插件 (Flash/Silverlight),就像在 FileReader
API 之前一样,JavaScript 无法访问文件系统。
关于javascript - 如何在更改时在 IE 中获取文件输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16900434/