web前端:下载文本文件javascript——下载某个文本类型的为——一段代码

下载文本文件javascript

const downloadTxtFile = () => {
    
    
    const element = document.createElement("a");
    const file = new Blob([text], {
    
    
      type: "text/plain",
    });
    element.href = URL.createObjectURL(file);
    element.download = "myFile.txt";
    document.body.appendChild(element);
    element.click();
  };

猜你喜欢

转载自blog.csdn.net/m0_46672781/article/details/128028001