我有一个能触发并接收e.target.files对象的函数,但我无法获取它的长度。 console.log(e.target.files.length)甚至不会触发。
<input multiple onChange={(e) => { this.handlefileupload(e) }} type="file" id="file" style={{ display: "none" }} />
this.handlefileupload = (e) => {
console.log(e.target.files)
console.log(e.target.files.length)
}
console.log(e.target.files)给出:
FileList {0: File(7105138), 1: File(7105138), 2: File(16792776), length: 3}0: File(7105138) {name: "image1.jpg", lastModified: 1544552208803, lastModifiedDate: Tue Dec 11 2018 10:16:48 GMT-0800 (Pacific Standard Time), webkitRelativePath: "", size: 7105138, …}1: File(7105138) {name: "imge2.jpg", lastModified: 1544468259102, lastModifiedDate: Mon Dec 10 2018 10:57:39 GMT-0800 (Pacific Standard Time), webkitRelativePath: "", size: 7105138, …}2: File(16792776) {name: "image3.png", lastModified: 1544558528903, lastModifiedDate: Tue Dec 11 2018 12:02:08 GMT-0800 (Pacific Standard Time), webkitRelativePath: "", size: 16792776, …}length: 3__proto__: FileList
答案 0 :(得分:1)
答案 1 :(得分:-1)
您似乎应该输入console.log(e.target.files.FileList.length)
。