我有这个脚本:
$.each($(this)[0].files, function(i, file){
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#display_image').prepend("<img src='"+e.target.result+"' />");
};
reader.readAsDataURL(input.files[count]);
}
count++;
});
所以它所做的只是简单地获取所有选定的文件路径multiple input并将其附加到img标签。
现在我想做的是给那个id等于变量的img,count但我的问题是前置函数在我的主each循环完成后运行,所以我总是得到相同的数字,就像3, 3, 3不是1, 2, 3我猜它的发生是因为reader.onload,但我'不知道如何以不同的方式做到这一点......