js导出数据为txt文件

function saveFile() {
  var data = document.querySelector('#text').value;
  // var data = '自定义的数据内容,可以是服务端返回滴!';
  var name = 'cdk.txt';
  exportRaw(data, name);
}
function exportRaw(data, name) {
  var urlObject = window.URL || window.webkitURL || window;
  var export_blob = new Blob([data]);
  var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
  save_link.href = urlObject.createObjectURL(export_blob);
  save_link.download = name;
  save_link.click();
}
posted @ 2019-07-24 15:31  叫我陆大人  阅读(3715)  评论(0编辑  收藏  举报

风萧萧兮易水寒