将字符串保存为文本文件
注:文件保存在当前电脑、下载文件夹中
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //保存 2 var mySave = function () { 3 console.log(event) 4 const content = 'a plain text.' 5 const blob = new Blob([ content ], {type: "text/plain;charset=utf-8"}) 6 const objectURL = URL.createObjectURL(blob) 7 var tempConfirm1 = confirm("objectURL:" +objectURL)//确认 8 const anchor = document.createElement('a') 9 anchor.href = objectURL 10 anchor.download = "plaintext.txt" 11 12 anchor.click() 13 14 URL.revokeObjectURL(objectURL) 15 16 }View Code
标签:const,objectURL,保存,js,文本文件,字符串,anchor From: https://www.cnblogs.com/automationanywhere/p/17490466.html