HTML JavaScript 读取多个本地文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<button class="save_button" onclick="f_load_files()">载入文件</button>
<input type="file" id="selectFiles" webkitdirectory/>
<body>
<script>
files_content = [];
async function f_load_files(){
var selectFiles = document.getElementById("selectFiles").files;
files_content =[];
for(var file of selectFiles)
{
const readFileAsync = file => new Promise(resolve => {
const reader = new FileReader();
reader.onload = evt => resolve(evt.target.result)
reader.readAsText(file)
})
files_content.push(await readFileAsync(file));
}
alert(files_content);
}
</script>
</body>
</html>