Created
January 3, 2017 09:38
-
-
Save ctosib/3151a184e616c8d9c80a01cf5f6c5dff to your computer and use it in GitHub Desktop.
如何利用javascript ReadFile API去讀取local的File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<input type="file" id="files" name="files" multiple /> | |
<div id="output"> | |
</div> | |
<script> | |
function openFile(event){ | |
var files = event.target.files; | |
var reader = new FileReader(); | |
reader.onload = function(){ | |
var text = reader.result; | |
console.log(text) | |
document.getElementById("output").innerText=text; | |
}; | |
reader.readAsText(files[0]); | |
} | |
document.getElementById("files").addEventListener("change",openFile,false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment