js 读取txt

这种方式只能在IE浏览器中使用(百度一堆都是这样的)

var fso = new ActiveXObject("Scripting.FileSystemObject");

var f = fso.OpenTextFile(filename,1);
我想要的是在谷歌浏览器或者其他浏览器使用(客户指不定什么浏览器)
而且想好按行读取txt
最终只能自己尝试完成老大说的读取txt的第二行的第一个
 
使用angular 的部分前端代码如下:

<input type="file" id="editimport" style="display: none;"
onchange="angular.element(this).scope().addstr(this)">
<a ng-click="onAction('editimport',r.Id)" ng-if="editing&&r.Id==panding.Id">
导入
</a>

js相关部分代码如下:

$scope.addstr = function (sender) {

var file = sender.files[0];     //具体怎么获取文件参考百度angular上传文件

$scope.file = file;

var reader = new FileReader();        //读取操作就是由它完成的。

reader.readAsText(file);        //读取文件的内容  file为文件
reader.onload = function () {

var ss = this.result.split("\r\n")[1].split(",")[0];       //\r\n换行 根据换行取  然后根据txt中每行中每两个元素中间的分隔符取数据 

$scope.$apply(function () {          //异步刷新页面

if ($scope.panding != null) {

$scope.panding.ExtendCode = ss;        //然后给相关数据赋值

return;
}
$scope.crt.ExtendCode = ss;
})
}

posted @ 2019-08-09 15:59  你小子嚣张呀  阅读(2339)  评论(0编辑  收藏  举报