JS纯前端实现文件保存
<body>
<a href="" id="a">click here to download your file</a>
<button onclick="download('file text', 'myfilename.txt', 'text/plain')">Create file</button>
</body>
<script>
function download(text, name, type) {
var a = document.getElementById("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
a.dispatchEvent(new MouseEvent('click', {'bubbles': false, 'cancelable': true}));
}
</script>