将textarea的内容保存为普通txt,扩展名为.csv [英] Save content of textarea as plain txt with .csv extension
本文介绍了将textarea的内容保存为普通txt,扩展名为.csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用 HTML5将内容保存为 txt
文件,其中包含 csv文件扩展名
?
它不应该是真正的csv。
Is there a way to save content as a txt
file with a csv file extension
using HTML5 ?
It shouldn't be a real csv.
类似 {type:'text / csv'};
不会在 {type:'text / plain'};
的地方工作。
Something like {type:'text/csv'};
wont work where {type:'text/plain'};
does.
推荐答案
a
标记的新下载
属性可以适用于您的这里有优势。 更多信息。
The a
tag's new download
property can work to your advantage here. More information.
概念证明:
<!doctype html>
<html>
<head>
<script type="text/javascript">
function save() {
var a = document.createElement('a');
with (a) {
href='data:text/csv;base64,' + btoa(document.getElementById('csv').value);
download='csvfile.csv';
}
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
</script>
</head>
<body>
<textarea id="csv"></textarea><button onclick="save()">Save</button>
</body>
</html>
这篇关于将textarea的内容保存为普通txt,扩展名为.csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文