js获取上传文件个数 以及名称

时间:2021-11-25 03:41:03
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="file" name="file" id="file" multiple="multiple" />
<div id="info_box"></div>
<script>
var fileDom = document.getElementById("file");
var infoBoxDom = document.getElementById('info_box'); fileDom.addEventListener("change", upload, false);
function upload(){
var list = this.files;
for( var i = 0 ; i < list.length ; i++ ){
infoBoxDom.innerHTML += list[i].name+"<br>";
}
infoBoxDom.innerHTML += list.length+'个文件';
}
</script>
</body>
</html>