<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>textarea文字存本地</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
</head>
<body>
<textarea name="hneirong" class="hhhj" rows="10" cols="50">123 是发发发对方是根深蒂固</textarea>
<br>
<a class="xz" href="#">保存文件</a>
<script>
function fake_click(obj) {
var ev = document.createEvent("MouseEvents");
ev.initMouseEvent(
"click", true, false, window, 0, 0, 0, 0, 0
, false, false, false, false, 0, null
);
obj.dispatchEvent(ev);
}
function export_raw(name, data) {
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;
fake_click(save_link);
}
var test=document.getElementsByClassName('hhhj')[0].value
console.log(test);
$('a').click(function() {
export_raw('数据.txt', test);
});
</script>
</body>
</html>
textarea文字存本地.txt,请问为啥只能能保存已有的文本,不能保存我输入的 呢
最新推荐文章于 2021-06-09 17:03:23 发布