运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>The Storage clear() Method</h1> <p>This example demonstrates how to use the clear() method to delete all session storage items for this domain.</p> <h2>Missing sessionStorage items?</h2> <p>Since you might not have any items stored in your session storage, we have added a script that creates some for you.</p> <button onclick="createItems()">Create session storage items</button> <h2>Remove Items</h2> <p>Click the button to delete the items:</p> <button onclick="deleteItems()">Delete 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() { sessionStorage.setItem("mytime", Date.now()); sessionStorage.setItem("myname", "John"); sessionStorage.setItem("myage", 36); } function deleteItems() { sessionStorage.clear(); } function displayItems() { var l, i; document.getElementById("demo").innerHTML = ""; for (i = 0; i < sessionStorage.length; i++) { x = sessionStorage.key(i); document.getElementById("demo").innerHTML += x + "<br>"; } } </script> </body> </html>