You can use <input type="file">
with multiple
attribute set, accept
attribute set to text/plain
; change
event ;FileReader
, for
loop.
var pre = document.querySelector("pre");
document.querySelector("input[type=file]")
.addEventListener("change", function(event) {
var files = event.target.files;
for (var i = 0; i < files.length; i++) {
(function(file) {
var reader = new FileReader();
reader.addEventListener("load", function(e) {
pre.textContent += "
" + e.target.result;
});
reader.readAsText(file)
}(files[i]))
}
})
<input type="file" accept="text/plain" multiple />
<pre>
</pre>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…