【发布时间】:2019-07-03 06:25:16
【问题描述】:
我希望我附加的 <tr> 元素在刷新页面后保持不变。
例如,当我注册用户时,数据会附加到表格行中。我想添加新用户,但我希望之前添加的用户也保留在表格中。
$("#tesdiq").click(function ()
$(".regForm").hide();
$(".myTable").show();
var ad = $("#ad").val();
var soyad = $("#soyad").val();
var email = $("#email").val();
var sheher = $("#sheher").val();
var infolar = ("<tr><td>" + ad + "</td>" + "<td>" + soyad + "</td>" + "<td>" + email + "</td>" + "<td>" + sheher + "<td>" + "<input type='checkbox' name='sil'></td></tr>");
$(".myTable table tbody").append(infolar);
localStorage.setItem("ad", ad);
localStorage.setItem("soyad",soyad);
localStorage.setItem("email",email);
localStorage.setItem("sheher",sheher);
我试过了,但它只能工作一次:
var myUser = localStorage.getItem("ad");
if (myUser) {
var yeni = ("<tr><td>" + localStorage.getItem("ad") + "</td>" +
"<td>" + localStorage.getItem("soyad") + "</td>" +
"<td>" + localStorage.getItem("email") + "</td>" +
"<td>" + localStorage.getItem("sheher") +
"<td>" + "<input type='checkbox' name='sil'></td></tr>");
$(".myTable table tbody").append(yeni);
}
【问题讨论】:
-
看起来你已经成功了。从本地存储中提取数据并填充表。似乎出了什么问题?
-
不知道怎么弄(
-
我尝试获取项目,但它似乎不起作用
-
这可能有助于显示您尝试了什么以及具体出了什么问题。包含一个证明问题的minimal, reproducible example 很有用。
-
我试过了,但它只工作一次 var myUser = localStorage.getItem("ad"); if(myUser){ var yeni = ("
"); $(".myTable table tbody").append(yeni); }" + localStorage.getItem("ad") + " " + "" + localStorage.getItem("soyad") + " " + "" + localStorage.getItem("email") + " " + "" + localStorage.getItem("sheher") + " " + "
标签: javascript html local-storage