2012-10-10 75 views
11

我在Internet Explorer中輸入(type =「file」)有問題(我只在8中測試過)。IE8 - 輸入(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中的「文件」未定義。有人知道如何使用JavaScript獲得這個「文件」?

編輯:文檔MSDN input type=file - 只有在IE10 files property

回答

14

的Internet Explorer 8不支持多個文件。這已經是already discussed here。您至少可以通過e.target.value獲取文件名。

+0

好吧我知道這不支持多個文件,但我怎樣才能獲得文件的信息? –

+0

@ThyagoQuintas e.originalEvent.dataTransfer.files [0]'適合你嗎? – Matthias

+0

不,我選擇文件後,dataTransfer爲空。 –

相關問題