我是一个完整的phoneGap。我动态创建了div
,我希望存储这些动态创建的div
window.localStorage.setItem
。我如何通过javascript执行此操作?
在页面加载时,我需要getItem
,即获取所有div并显示它们。
代码:动态创建div:
var addDiv = document.createElement("div");
addDiv.id = "div_multi";
document.getElementById("add-questions").appendChild(addDiv);
var btnRemove = document.createElement("input");
btnRemove.type = "button";
btnRemove.value = "Delete";
btnRemove.setAttribute("onclick", "deleteSelectedQuestion(this)");
addDiv.appendChild(btnRemove);
var btnSave = document.createElement("input");
btnSave.type = "button";
btnSave.value = "Save";
btnSave.setAttribute("onclick", "saveSelectedQuestion(this)");
addDiv.appendChild(btnSave);
var btnEdit = document.createElement("input");
btnEdit.type = "button";
btnEdit.value = "Edit";
btnEdit.setAttribute("onclick", "editSelectedQuestion(this)");
addDiv.appendChild(btnEdit);
var lblQuestion = document.createElement("div");
lblQuestion.innerText = "Question. ";
addDiv.appendChild(lblQuestion);
var questionText = document.createElement("input");
questionText.type = "text";
questionText.id = "multi_question" + i;
addDiv.appendChild(questionText);
var lblAnswer = document.createElement("div");
lblAnswer.innerText = "Answer. ";
addDiv.appendChild(lblAnswer);
我如何存储?