下面是如何使用
readAsBinaryString()从的FileReader API来加载本地文件。
<p>Select local CSV File:</p><input id="csv" type="file"><output id="out"> file contents will appear here</output>
基本上,只需要侦听change事件
<input type="file">并调用readFile函数即可。
var fileInput = document.getElementById("csv"), readFile = function () { var reader = new FileReader(); reader.onload = function () { document.getElementById('out').innerHTML = reader.result; }; // start reading the file. When it is done, calls the onload event defined above. reader.readAsBinaryString(fileInput.files[0]); };fileInput.addEventListener('change', readFile);jsFiddle



