Skip to content Skip to sidebar Skip to footer

How To Loop This Function?

Thanks to some help on here I have a way of previewing images selected for and upload using:

Solution 1:

input.files is a FileList, which acts like an array. You can use jQuery.each on it like any other array.

Solution 2:

You just need to loop over the last line, where the file is selected.

functionreadURL(input) {
    var reader = newFileReader();
    reader.onload = function (e) {
        var container = $('#previews');
        var image = $('<img>').attr('src', e.target.result).width(150);
        image.appendTo(container);
    };

    $.each(input.files,function(i) {
        reader.readAsDataURL(input.files[i]);
    });
}

Post a Comment for "How To Loop This Function?"