html javascript读取 文件内容
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>文件读取</title> </head> <body> <input type="file"> <script> function get_html_css_fun( info ){ info = info.replace("kd.Reg(\"PK_机构单位\", {","") var last = info.lastIndexOf("});") info = info.substring(0,last) return info } function get_html(info){ //console.log(info) start = info.indexOf("html:[") end = info.indexOf("css:[") //console.log(start) //console.log(end) info = info.substring( (start+"html:[".length ), (end- "css:[".length - "],".length ) ) return info } function get_css(info){ //console.log(info) start = info.indexOf("css:[") end = info.indexOf("fun: function() {") console.log(start) console.log(end) info = info.substring( (start+"css:[".length ), (end ) ) last = info.lastIndexOf("],") info = info.substring(0, last) return info } function get_fun(info){ start = info.indexOf("fun: function() {") last = info.lastIndexOf("}") info = info.substring(start + "fun: function() {".length, last) return info } var input = document.querySelector("input") input.onchange=function(){ /* 查看this里的属性 for(var key in this) { console.log(this[key]); } */ // 获取文件 var files = this.files[0]; // 开始读取,创建读取器 var reader = new FileReader(); // 开始读取 reader.readAsText(files) // 文件读取完成后,获取文件内容 reader.onload = function() { // 获取结果 //console.log(reader.result); var todo_text = reader.result ; var html_css_fun = get_html_css_fun( todo_text ) //console.log(html_css_fun) var text_html = get_html( html_css_fun ); console.log("------------------------text_html------------------------") console.log(text_html) var text_css = get_css( html_css_fun ); console.log("------------------------text_css------------------------") console.log(text_css ) var text_fun = get_fun( html_css_fun ); console.log("------------------------text_fun------------------------") console.log(text_fun ) } } </script> </body> </html>