// 获取文本内容
const text = document.getElementById('copy').innerText
// 创建一个包含文本内容的 Blob 对象
const blob = new Blob([text], { type: 'text/plain' });
// 创建下载链接
const downloadUrl = URL.createObjectURL(blob);
// 创建 <a> 元素并设置属性
const link = document.createElement('a');
link.href = downloadUrl;
link.download = 'fileName.docx';
// 模拟点击下载
link.click();
原生js实现将文本生成Word 文档并下载
于 2023-08-23 09:37:05 首次发布