簡體   English   中英

javascript為什么我無法從文件數組中獲取文件名?

[英]javascript why I could not get the name of file from files array?

我有關於input | file對象的簡單javescript:

  var upfiles=new Array();

  function addfile(files){
      upfiles.push(files);
      alert(upfiles[0].name);  //undefined
      alert(files[0].name);    //can get file name
      upfiles[0].prop("name"); //can get file name
      alert(upfiles.length);    //1
  }

我不知道為什么upfiles[0].name只給我返回undefined,而upfiles[i]).prop("name")工作。 兩種方法之間的區別?

你試過了嗎

upfiles[0][0]

看到您將文件數組推入另一個數組等時

您可能要使用concat而不是在此處push ,以創建一維數組。

我希望我可以發表評論...

我會在chrome中嘗試,然后放入

console.log(upfiles);

在發出警報之前...只需在控制台中檢查對象的結構。 當我使用沒有詳細文檔的框架時,我不得不像這樣檢查它們的功能輸出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM