如何在Struts2中上传多个文件之前显示选定的文件名? [英] How to display selected file names before uploading multiple files in Struts2?
本文介绍了如何在Struts2中上传多个文件之前显示选定的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< s:file name =filesmultiple =multiple />
当我选择多个文件时,它会显示文件的数量,例如。 3个文件。
项目要求是用户应该能够查看上传前选择的文件。
是否可以在列表中显示选定的文件名,或者可以在控件本身显示?
解决方案您可以使用
< input type =file/>的HTML5 文件
属性 code $>元素如下:
$ b
updateList = function(){var input = document.getElementById ('文件'); var output = document.getElementById('fileList'); output.innerHTML ='< ul>'; for(var i = 0; i< input.files.length; ++ i){output.innerHTML + ='< li> + input.files.item(i).name +'< / li> ; } output.innerHTML + ='< / ul>';}
< input type =filename =fileid =filemultiple onchange =javascript:updateList()/>< br />所选文件:< div id =fileList >< / div>
I am using Struts2 to upload multiple files:
<s:file name="files" multiple="multiple" />
When I select multiple files it displays the number of files, eg. 3 files.
The project requirements are that the user should be able to see what files he selected before uploading.
Is it possible to display the selected files names in a list or maybe in the control itself ?
解决方案 You can use the HTML5 files
property of the <input type="file" />
element like follows:
updateList = function() {
var input = document.getElementById('file');
var output = document.getElementById('fileList');
output.innerHTML = '<ul>';
for (var i = 0; i < input.files.length; ++i) {
output.innerHTML += '<li>' + input.files.item(i).name + '</li>';
}
output.innerHTML += '</ul>';
}
<input type="file" name="file" id="file" multiple
onchange="javascript:updateList()" />
<br/>Selected files:
<div id="fileList"></div>
这篇关于如何在Struts2中上传多个文件之前显示选定的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文