运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Storage setItem() Method</h1> <p>This example demonstrates how to use the setItem() method to set the value of a specified session storage item.</p> <button onclick="createItem()">Set session storage item</button> <h2>Get the value</h2> <p>Click the button to get the item value:</p> <button onclick="readValue()">Get the item value</button> <p id="demo"></p> <script> function createItem() { sessionStorage.setItem("test1", "Lorem ipsum"); } function readValue() { var x = sessionStorage.getItem("test1"); document.getElementById("demo").innerHTML = x; } </script> </body> </html>