2013-06-03 34 views
4

我需要获取加载文件才能输入。 此代码在Chrome,Opera和Firefox,但不与IE:如何在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。感谢您的提前。

回答

1

您使用的是哪个版本的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没有任何访问文件系统的权限。

+0

我有9个或更高版本。 9如何解决这个问题? – Andrew

+3

@Andrew:[在IE 9中FileReader()的Shim](http://stackoverflow.com/questions/11089897/shim-for-filereader-in-ie-9) – apsillers

+0

感谢您的解释。此问题已关闭。 – Andrew

相关问题