我想从字符串创建一个文本文件.目前我正在使用一个函数,它接受一个数组并使其成为一个字符串然后使用该字符串我想创建一个用户下载的本地文本文件.我尝试过使用这种方法
function createFile(){ //creates a file using the fileLIST list
var output= 'Name \t Status\n'+ fileLIST[0][0].name+'\t'+fileLIST[0][1]+'\n';
var Previous = fileLIST[0];
for (var i=1; i<fileLIST.length; i++)
if (fileLIST[i][1] =='none' || fileLIST[i][1] == Previous[1])
continue
else {
Previous = fileLIST[i]
output = output + fileLIST[i][0].name +'\t'+fileLIST[i][1] + '\n';}
window.open("data:text/json;charset=utf-8," + escape(output));//should create file
display(); }
Run Code Online (Sandbox Code Playgroud)
我使用chrome作为我的浏览器.我也更喜欢JS或HTML5的答案.
先感谢您