gpt4 book ai didi

javascript - 在 Web 存储中检索 JSON 数据不起作用

转载 作者:行者123 更新时间:2023-11-29 17:20:18 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Storing Objects in HTML5 localStorage

我正在尝试存储两个文本字段中给出的 JSON 数据、姓名和电话号码,然后稍后(在页面刷新后)使用以下代码检索并打印相同字段上的数据。

        function saveData() {
var saveD = {
name: document.getElementById("name").value,
phone: document.getElementById("phone").value
};

window.localStorage.setItem("info", saveD);
}
var storedData = window.localStorage.getItem("info");

document.getElementById("name").value = storedData.name;
document.getElementById("phone").value = storedData.phone;

怎么了?我在两个领域都得到“未定义”。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com