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();
}
一起加油吧,奥利给!