input 的multiple 上传多个文件
W3School TIY 在线测试工具:http://www.w3school.com.cn/tiy/t.asp?f=html5_input_multiple
https://blog.csdn.net/yelin232812/article/details/78062350
配置SpringMVC环境在WEB-INF下:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600" />
<property name="maxInMemorySize" value="4096" />
<property name="defaultEncoding" value="UTF-8"></property>
</bean>
1.在input标签中加入 multiple 属性,可以在一个输入框中选择多个文件进行上传
<input type="file" name="img" multiple="multiple" />
当然,这样也是一样的:
<input type="file" name="img" multiple />
2.很多时候上传的时候,我们要限制一下上传文件类型(在windows中主要是限制后缀名),或者是把选择的文件名(路径)输出到当前页面,这需要用js取得选择文件的名字:
document.getElementById("input").files[i].name
3. easyui中如何创建和遍历一个数组:
var mfs = [];
for(var i=0; i< mfs.length; i++){
if (mfs[i] != null && mfs[i] != '' && !/.(xlsx)$/.test(mfs[i])){
$.messager.alert('Warning','The type of file can only be 2007 Excel', mfs[i]);
return false;
}
}
最后注意:Internet Explorer 9及更早 IE 版本不支持 input 标签的 multiple 属性。
附一段Demo:
<!DOCTYPE HTML>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body>
<script type="text/javascript">
function onc(){
var files = document.getElementById("alcm_file").files;
for(var i=0; i< files.length; i++){
alert(alcm_file.files[i].name);
}
}
</script>
<form action="/example/html5/demo_form.asp" method="get">
选择图片:<input type="file" id="alcm_file" name="input" onchange="onc()" multiple="multiple" />
<input type="submit" />
</form>
<p>请尝试在浏览文件时选取一个以上的文件。</p>
</body>
</html>

浙公网安备 33010602011771号