downloadJsonOrTxt('a.json', JSON.stringify({a:"b"}))
function downloadJsonOrTxt(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
} else {
pom.click();
}
}
js保存json/txt文件
最新推荐文章于 2024-07-22 16:16:18 发布