我一直在試圖解決這與我有HTML5的基本知識,但我想要做的是允許訪問者在一個頁面上編輯多個表單域,然後保存它們使用localstorage可以在重新訪問該頁面時查看這些更改。contenteditable&localstorage與多個字段的問題
這是我走到這一步,從教程中使用:http://www.developerdrive.com/2012/06/allowing-users-to-edit-text-content-with-html5/
正在發生的事情是場二是覆蓋字段是不是我期望的結果一個&。 預期結果=編輯完成後,每個可編輯區域應保留其自己的編輯狀態。有在頁面上約63場,但爲了簡單起見,我已經包括2
的JavaScript:
<script type="text/javascript">
function saveEdits() {
//get the editable element
var editElem = document.getElementById("edit");
var editElem = document.getElementById("edit2");
//get the edited element content
var userVersion = editElem.innerHTML;
//save the content to local storage
localStorage.userEdits = userVersion;
//write a confirmation to the user
document.getElementById("update").innerHTML="Edits saved!";
}
function checkEdits() {
//find out if the user has previously saved edits
if(localStorage.userEdits!=null)
document.getElementById("edit").innerHTML = localStorage.userEdits;
}
</script>
HTML:
<body onload="checkEdits()">
<div id="edit" contenteditable="true">LASTNAME</div>
<div id="edit2" contenteditable="true">FIRSTNAME</div>
<input type="button" value="save my edits" onclick="saveEdits()"/>
<div id="update"> - Edit the text and click to save for next time</div>
幫助會特別欣賞的方式和內容,以添加相應的將來可能包含更多可編輯的字段。
'edit2'的目的是什麼? –
@ArunPJohny這是第二個表單域,它允許用戶輸入附加信息。圖片模板系統 - 允許頁面上的許多內容直接在頁面上進行編輯。 – user1823055
它似乎在這裏工作正常http://jsfiddle.net/arunpjohny/b36tH/ –