我设法得到这个工作,但是当变量实际上是一个多个对象的数组,你可以用blob写入每一行时,如何实际实现这一点?
var line1 = "firstline";
var line2 = "secondline";
var blob = new Blob([line1 + "\r\n", line2], {type: "application/txt"});
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.download = "test.txt";
a.href = url;
a.textContent = "Download test.txt";
document.getElementById('test').appendChild(a);
答案 0 :(得分:1)
var arr = ['firstline', 'secondline', 'thirdline'];
var lineConcat = arr.join("\r\n");
var blob = new Blob([lineConcat], {type: "application/txt"});