📜  如何将js中的var设置为下载 - Html代码示例

📅  最后修改于: 2022-03-11 14:52:51.380000             🧑  作者: Mango

代码示例1
var textToSave = 'this is a test';

var hiddenElement = document.createElement('a');

hiddenElement.href = 'data:attachment/text,' + encodeURI(textToSave);
hiddenElement.target = '_blank';
hiddenElement.download = 'myFile.txt';
hiddenElement.click();