作者:Andiry舍甫琴科 | 来源:互联网 | 2023-09-11 19:59
function saveTextAsFile() {
var textToSave = document.getElementById("inputTextToSave").value;
var textToSaveAsBlob = new Blob([textToSave],{ type: "text/plain" });
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.Onclick= countClicks;
// downloadLink.Onclick= destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
function countClicks() {
if (localStorage.clickcount >= 5) {
localStorage.clickcount = 0; // reset count
localStorage.clickcount1++; // increase next count
}
if (typeof (Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount) + 1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "Number of Notes Saved:" + localStorage.clickcount ;
} else {
document.getElementById("result").innerHTML = "Sorry,your browser does not support web storage...";
}
}
我成功地从Blob下载了文本文件。但是,我希望将注释保存在网站上,但找不到正确的解决方案。
这是我到目前为止尝试过的代码。我只能计算笔记的数量,而不是将笔记保存在网站本身中。请帮忙。