如何在文件也反映在FormData对象的FileList对象上设置File对象和Length属性?
.files
<input type="file">
FileList
<input type="file">
.files
DataTransfer.files
FileList
Symbol.iterator
File
.files
.length
0
<form>
<input type="file">
.files
File
.size
0
.
File
FileList
.length
FileList
FormData()
const input = document.createElement("input");const form = document.createElement("form");const [...data] = [ new File(["a"], "a.txt"), new File(["b"], "b.txt")];input.type = "file";input.name = "files";input.multiple = true; // set `File` objects at `FileList`input.files[Symbol.iterator] = function*() { for (const file of data) { yield file };};form.appendChild(input);const fd = new FormData(form);for (const file of input.files) { console.log(file); // `File` objects set at `data`}for (const [key, prop] of fd) { // `"files"`, single `File` object having `lastModified` property // set to a time greater than last `File` object within `data` // at Chromium 61, only `"files"` at Firefox 57 console.log(key, prop); }console.log(input.files.length); // 0
慕丝7291255
相关分类