解决方案如下:

var csvString = 'ı,ü,ü,ğ,ş';
var universalBOM = "\uFEFF";
var a = window.document.createElement('a');
a.setAttribute('href', 'data:text/csv; charset=utf-8,' + encodeURIComponent(universalBOM+csvString));
a.setAttribute('download', 'example.csv');
window.document.body.appendChild(a);
a.click();

扩展:
导出txt文件如下

var csvString = 'ı,ü,ü,ğ,ş';
var a = window.document.createElement('a');
a.setAttribute('href', 'data:text/plain; charset=utf-8,' + encodeURIComponent(csvString));
a.setAttribute('download', 'example.txt');
window.document.body.appendChild(a);
a.click();
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐