常规方式是通过 ajax:
fetch(<文本 url>).then(data=>data.text()).then(text=>{
// add your code here
})
js读取txt文件:
function readFile(filename){var fso = new ActiveXObject("Scripting.FileSystemObject")
var f = fso.OpenTextFile(filename,1)
var s = ""
while (!f.AtEndOfStream)
s += f.ReadLine()+"\n"
f.Close()
return s
}
js写txt文件:
function writeFile(filename,filecontent){var fso, f, s
fso = new ActiveXObject("Scripting.FileSystemObject")
f = fso.OpenTextFile(filename,8,true)
f.WriteLine(filecontent)
f.Close()
alert('ok')
}