JavaScript - js生成 txt 文件
/**
* 方法定义
*/
function download(filename, text) {
var element = document.createElement('a');
element.style.display = 'none';
var content = encodeURIComponent(text);
element.setAttribute('href', `data:text/plain;charset=utf-8,${content}`);
element.setAttribute('download', filename);
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// 方法调用
download("hello.txt", "Type txt file content here.");
标签:text,JavaScript,js,element,content,download,txt
From: https://www.cnblogs.com/eddyz/p/17831824.html