如何在Struts2中上传多个文件之前显示选定的文件名

如何在Struts2中上传多个文件之前显示选定的文件名

本文介绍了如何在Struts2中上传多个文件之前显示选定的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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中上传多个文件之前显示选定的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:17