作者kolocoyima (客倌來看看!)
看板Ajax
標題[問題] prototype.push.apply 新增到陣列問題
時間Sun Dec 21 20:14:25 2014
var arr = new Array ("001","002","003");
var file = document.getElementById('file').files[0];
if (file)
{
i = String(file.name);
arr.prototype.push.apply([i]);
}
利用file button選取檔案抓取檔名
並且把檔名強制轉為字串
然後使用push新增到陣列
請問這樣寫對嗎?
for(j=0;j<=arr.length;j++)
{
i = String(file.name);
arr.prototype.push.apply(???);
}
document.write(arr);
}
如果要使用for迴圈的話是要這樣寫嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.231.6.103
※ 文章網址: http://webptt.com/m.aspx?n=bbs/Ajax/M.1419164069.A.890.html
※ 編輯: kolocoyima (61.231.6.103), 12/21/2014 20:16:49
1F:推 oToToT: 不是只要arr.push就好 12/21 23:43
2F:→ swijo: var arr=[]; ...arr.push(file[0].name); 12/22 02:28
3F:→ swijo: s 12/22 02:28
4F:推 mrbigmouth: 沒事不要亂用建構式 會很慘 12/22 08:32