运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Window Object</h1> <h2>The localStorage Property</h2> <p><button onclick="clickCounter()" type="button">Click me!</button></p> <p>Number of clicks:</p> <p id="demo"></p> <p>Click the button to see the counter increase.</p> <p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p> <script> clickCounter(); function clickCounter() { if (localStorage.clickcount) { localStorage.clickcount = Number(localStorage.clickcount)+1; } else { localStorage.clickcount = 1; } document.getElementById("demo").innerHTML = localStorage.clickcount; } </script> </body> </html>