<script> function readCsv() { const file = $("#uploadFile")[0].files[0]; if (file.type != "text/csv") { alert("文件类型错误"); return; } var reader = new FileReader(); const data = []; reader.onload = function () { const result = reader.result; let lines = result.split("\r\n"); lines.map(function (item, index) { let line = item.split(","); data.push(line); }); console.log(data); }; reader.readAsText(file); } </script> <body> <input type="file" name="file" id="uploadFile" onchange="readCsv(this);" /> </body>
标签:function,const,FileReader,js,result,file,reader,csv From: https://www.cnblogs.com/caroline2016/p/16905555.html