调用 FileReader 加载本地文件
<script type="text/javascript">
$(document).ready(function() {
var traces = [];
// 加载
$("#loadFile").on("change", function() {
var targetFile = this.files[0];
var name = targetFile.name;
var size = targetFile.size;
var reader = new FileReader();
reader.readAsText(targetFile);
reader.onload = function() {
console.log("加载完成");
$("#kcal_result_show").html('');
var _result = this.result.split(/\\n|\n/);
traces = [];
for (var i = 0, length = _result.length; i < _result.length; i++) {
traces.push({'cl': _result[i]})
}
};
reader.onerror = function() {
console.log("加载失败");
}
});
});
</script>