且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用JavaScript从文本创建文件

更新时间:2023-11-15 14:20:58

将文件扩展名添加到文件名中.像这样

Add the file extension to the name of the file. Like this

a.download = filename + ".txt";

查看Blob对象为type属性输入'plain/text'的文档以指定文本,您可能需要注意,将Blob声明更改为

Looking at the docs the Blob object takes in 'plain/text' for the type attribute to specify text this may be something you should keep an eye on, change Blob declaration to

var file = new Blob([data], {type: 'plain/text'});