W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <head> <script> function clickCounter() { if(typeof(Storage) !== "undefined") { if (localStorage.clickcount) { localStorage.clickcount = Number(localStorage.clickcount)+1; } else { localStorage.clickcount = 1; } document.getElementById("result").innerHTML = "您已经点击这个按钮 " + localStorage.clickcount + " 次。"; } else { document.getElementById("result").innerHTML = "抱歉!您的浏览器不支持 Web Storage ..."; } } </script> </head> <body> <p><button onclick="clickCounter()" type="button">请点击这里!</button></p> <div id="result"></div> <p>请点击按钮使计数器递增。</p> <p>请关闭浏览器或标签页,然后再试一次,计数器将继续计数(不会重置)。</p> </body> </html>