我目前有一個編輯器,允許用戶保存他們的編輯,通過使用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