var readTxt = (function(w) {
//常量
var __DEFAULT__ = {
exp: {
trim: /\s/, //匹配空格
rn: /\r\n/g //匹配换行
},
errorMsg: {
readError: "读取文件出错!",
interruptError: "读取文件异常中断!"
}
};
//保存txt解析后的数据
var ary = [],
//存储对象keys的数组
attrs = [],
//存储所有行的数据的数组
vals = [];
function read(file, successFn, beforeFn, isShowProgress) {
var reader = new FileReader();
//开始读取数据之前触发
reader.onloadstart = function() {
console.time();
beforeFn && beforeFn();
};
//读取中触发(读取进度)
reader.onprogress = function(e) {
debugger;
if(typeof isShowProgress === 'boolean' && isShowProgress) {
var loaded = e.loaded,
total = e.total,
percent = parseFloat(loaded/total).toFixed(2);
showProgress(percent);
}
};
function showProgress(p) {
console.log("打印p:");
console.log(p);
progress.style.display = 'block&#
html5 filereader读取txt文件
最新推荐文章于 2023-08-25 07:08:51 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)