【发布时间】:2018-09-24 18:53:30
【问题描述】:
我有两个页面,分别是“form.html”和“data.html”。 在“form.html”中,我有以下 html 和 jquery 代码:
html:
<form id="myForm">
<label>Enter Name: <input type="text" id="txtName" /></label>
<button id="_save">Save</button>
</form>
jquery:
$(document).ready(function() {
$("#_save").on('click', function() {
localStorage.name = $('#txtName').val();
console.log("data saved");
});
});
在 "data.html" 我有以下代码:
html:
<div id="dataContainer"></div>
"jquery:"
$(document).ready(function() {
loadData();
});
function loadData() {
$('#dataContainer').append('<div><h5>' + localStorage.name + '</h5></div>');
localStorage.removeItem(name);
}
当前情况: 在 form.html 我正在尝试使用 click fn 和 localstorage 存储表单数据。在 data.html 中,我试图在文档就绪功能上获取存储的数据。删除之前的数据并加载新输入的数据。
问题: 我正在尝试在 data.html 中附加所有名称,这些名称存储在 form.html 页面中。我需要之前输入的所有名称。 (不应删除先前输入的数据。) 请帮助我在我失踪的地方或任何建议。
【问题讨论】:
标签: jquery html local-storage