Jquery在IE 9中导致错误

Rav*_*Ram 0 arrays jquery internet-explorer

我有以下HTML代码

<label class="fileinput-button" id="fileUpload-label">
   <span class="btn btn-add" id="fileUpload-span">Add a file..</span>
      <div id="fileinput-outer">
         <input type="file" name="files[]" id="fileUpload">
      </div>
</label>
Run Code Online (Sandbox Code Playgroud)

然后我使用Jquery获取Input type = File的文件列表

$('#fileUpload').live('change', function () {
    $.map($('#fileUpload').get(0).files, function (file) { 
        $('#fileList')
            .append(CreateFileList(file.name, true));
        });
 });
Run Code Online (Sandbox Code Playgroud)

这在Chrome和Firefox中运行良好,但在IE中错误是

Unable to get value of the property 'length': object is null or undefined
Run Code Online (Sandbox Code Playgroud)

所以我开始麻烦并且有这个代码

var arrFiles[];
arrFiles = $('#fileUpload').get(0).files;
    if(arrFiles.length === 0) {
        alert('empty');    
    } else {
       alert('has value');    
    }
Run Code Online (Sandbox Code Playgroud)

Chrome和Firefox - 代码和警报按预期工作,但IE仍然会引发错误

Unable to get value of the property 'length': object is null or undefined
Run Code Online (Sandbox Code Playgroud)

似乎IE可能与Jquery Get有问题..

任何人都知道如何在有或没有Jquery的IE中修复此错误?

Jua*_*des 5

jQuery().get工作正常,你没有打破它.但是,IE 9 没有files属性<input type=file />,它是在IE 10中引入的.请参阅此示例http://jsfiddle.net/RtqnZ/

你也错过了multiple你的财产input

参考:http://msdn.microsoft.com/en-us/library/ie/hh772931(v = vs.85).aspx