我想用ajax上传多个文件。此输入字段放置在 multipart/form-data 表单中:
<input type="file" id="upload" accept="image/jpeg" name="file[]" multiple >
在此代码中,add_image 函数中文件数组的大小变为未定义。为什么?
<小时/>function add_image(images, i) {
var image = images.item(i);
var total = images.lenght;
console.log(total);
if (i < total) {
$.ajax({
...
});
}
}
$(document).ready(function () {
$('#upload').on('change', function () {
console.log(this.files.length);
add_image(this.files, 0);
});
});
最佳答案
第 3 行 lenght
存在拼写错误,而不是 length
。
关于javascript - 作为参数传递时丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33266216/