js读取上传的文件内容

来源:互联网 发布:手机上编写c语言的软件 编辑:程序博客网 时间:2024/05/21 02:50
this.upload = function() {      var objFile = document.getElementById("upfile");    var files = $('#upfile').prop('files');//获取到文件列表    if(files.length == 0){        alert('请选择文件');    }else{        var reader = new FileReader();//新建一个FileReader        reader.readAsText(files[0], "UTF-8");//读取文件         reader.onload = function(evt){ //读取完文件之后会回来这里            currentPageInst.jumpToCert(evt.target.result); // 读取文件内容        }    }}this.jumpToCert= function(certName){    var postData;    jsonObjInit();    jsonObjPush("action", 'import');    jsonObjPush("certName", encodeURI(certName));//encodeURI为转码    postData = jsonObjEnd();    setCfg("ctCertcaSet.json", postData, updateAllCfg);}