我希望有人可以为我更新这个JSFiddle代码,以便为多个选定的图像显示多个输入框。
适用于单张图像。
https://jsfiddle.net/WWNnV/609/
document.getElementById('upload').onchange = uploadOnChange;
function uploadOnChange() {
var filename = this.value;
var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex + 1);
}
document.getElementById('filename').value = filename + "_date";
}

<input id="upload" type="file" multiple="multiple" />
<input id="filename" type="text" />
&#13;
任何帮助将不胜感激。
答案 0 :(得分:1)
document.getElementById('upload').onchange = uploadOnChange;
function uploadOnChange() {
var text = this.value;
if (this.files && this.files.length > 1) {
var filenames = [];
for(i=0; i<this.files.length; i++) {
var filename = this.files[i].name;
var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex + 1);
}
filenames.push(filename);
}
text = filenames.join();
}
document.getElementById('filename').value = text;
}
JSFiddle:https://jsfiddle.net/bartvanderwal/Lego5bcp/4/
TODO:创建多个输入而不是连接文件名
答案 1 :(得分:0)