我正尝试在多张图片上传中也显示图片名称。如果单选,它可以工作,但多选图片名称,则重复。请检查我的小提琴。我也在尝试显示图像路径
最佳答案
您只需要更改:
工作提琴:https://jsfiddle.net/1kojL0pk/
var f = $('.trnsupload').prop("files")[0]['name'];
至
var f = $('.trnsupload').prop("files")[i]['name'];
//完整代码:
window.Transfer = function (input) {
if (input.files && input.files[0]) {
$(input.files).each(function (i) { // add index over here
var f = $('.trnsupload').prop("files")[i]['name']; // access file using i-th index
var reader = new FileReader();
reader.readAsDataURL(this);
reader.onload = function (e) {
$("#Viewer").append("<div class='imageContainer'><img onclick='changeIt(this)' class='thumb img-thumbnail' src='" + e.target.result + "'> <span class='MultiFile-title'>" + f + "</span> <span class='loader'><img src='../../Images/ajax-loader.gif' /></span> <span class='closeCover glyphicon glyphicon-remove'></span></div>");
}
});
}
}