我目前有一个编辑器,允许用户保存他们的编辑,通过使用localstorage和一个提示,询问他们的编辑标题。我已将标题附加到可以访问它的表格。链接一个附加标题
简而言之,如果他们将编辑保存为“主题1”,则“主题1”将出现在网页侧面。现在我想知道,如何将这个“主题1”链接到他们的编辑?这样,当他们点击它时,编辑会显示他们的编辑并允许他们再次编辑它?
<!-- Function to save the user's input inside editor1 -->
function saveEdits() {
var editElem = document.getElementById("editor1");
var userVersion = editElem.innerHTML;
localStorage.userEdits = userVersion;
var title = prompt("What would you like your title to be?");
localStorage.title = title;
document.getElementById("update").innerHTML = "Edits saved!";
var theDiv = document.getElementById("Contentable");
var content = document.createTextNode(title);
theDiv.appendChild(content);
}
<!-- Function to check if the user has any saved input -->
function checkEdits() {
if(localStorage.userEdits != null)
document.getElementById("editor1").innerHTML = localStorage.userEdits;
}
我在阵列码添加,但一个错误显示出来:遗漏的类型错误:titles.push不是一个函数 – cosmo
你得到上面的部分检查'titles == null'是否被触发,如果这样会创建一个新的数组? – AlienHoboken
是的,它在我的代码中。我已经检查了好几次 - 这不是复制和粘贴的问题。 – cosmo