本文由 资源共享网 – ziyuan 发布,转载请注明出处,如有问题请联系我们![免费]把文本内容导出到txt文件的js函数及下载文件的js函数
资源语言: 中文
把文本内容导出到txt文件的js函数:
function downloadFile(fileName, data, type = 'application/octet-stream') {
const blob = new Blob([data], { type });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}
// 使用示例:
const fileData = 'Hello, this is the file content!'; // 假设这是你的文件内容(字符串、ArrayBuffer等)
downloadFile('myfile.txt', fileData);下载文件的js函数:
function downloadFileFromServer(url, fileName) {
fetch(url)
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
})
.catch(error => console.error('Error downloading file:', error));
}
// 使用示例:
const fileUrl = 'https://example.com/path/to/your/file.txt'; // 你的文件URL
downloadFileFromServer(fileUrl, 'myfile.txt');与《[免费]把文本内容导出到txt文件的js函数及下载文件的js函数》相关的《插件》
jQuery一键导出Excel表格文件代码
这是一款非常实用的jQuery一键导出Excel表格文件代码,点击按钮将网页表格转换为Excel表格保存。文章来自陌佑网www.zjw13.xyz转载请注明出处,并保留本链接,谢谢!
2 161639 0
jQuery导出excel表格文件pdf文件CSV文件代码
这是一款非常强大实用的jQuery将网页表格数据导出excel表格文件、pdf文件和CSV文件代码,点击按钮一键导出,还支持网页打印、查询数据等。文章来自陌佑网www.zjw13.xyz转载请注明出处,谢谢!!!
2 161242 0
jQuery将网页表格转换为excel文件导出代码
jQuery将网页表格转换为excel文件导出代码,可添加表格数据,表格样式是基于bootstrap响应式的。文章来自陌佑网www.zjw13.xyz转载请注明出处,谢谢!!!
4 161511 0
![点击放大 [免费]把文本内容导出到txt文件的js函数及下载文件的js函数](https://www.08i8.com/uploadfile/autoimg/202405/29/957090654612038415.jpg)

