W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>通过 local storage 存储并取回数据:</h1> <p id="demo"></p> <script> var myObj, myJSON, text, obj; // 存储数据: myObj = { "name":"Bill Gates", "age":62, "city":"Seattle" }; myJSON = JSON.stringify(myObj); localStorage.setItem("testJSON", myJSON); // 取回数据: text = localStorage.getItem("testJSON"); obj = JSON.parse(text); document.getElementById("demo").innerHTML = obj.name; </script> </body> </html>