运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html> <body> <h1>The Storage Object</h1> <p>This example demonstrates how to loop through all the local storage items for this domain.</p> <h2>Missing localStorage items?</h2> <p>Since you might not have any items stored in your local storage, we have added a script that creates some for you.</p> <button onclick="createItems()">Create local storage items</button> <h2>Display Items</h2> <p>Click the button to display all items:</p> <button onclick="displayItems()">Display items</button> <p id="demo"></p> <script> function createItems() { localStorage.setItem("mytime", Date.now()); localStorage.setItem("myname", "John"); localStorage.setItem("myage", 36); } function displayItems() { var l, i; document.getElementById("demo").innerHTML = ""; for (i = 0; i < localStorage.length; i++) { x = localStorage.key(i); document.getElementById("demo").innerHTML += x + "<br>"; } } </script> </body> </html>