<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="result"></div> <div id="result2">显示点击次数</div> <script> if(typeof(Storage)!=="undefined"){ localStorage.setItem("last","gggg");//存储 document.getElementById("result").innerHTML=localStorage.getItem("last"); //获取 } else{ document.getElementById("result").innerHTML=localStorage.getItem("你的浏览器不支持"); //获取 } //存储访问次数 if(localStorage.pagecount){ localStorage.pagecount=Number(localStorage.pagecount)+1; } else{ localStorage.pagecount=1; } document.write("vistit "+localStorage.pagecount+" times"); //sessionStorage if(sessionStorage.pagecount){ sessionStorage.pagecount=Number(sessionStorage.pagecount)+1; } else{ sessionStorage.pagecount=1; } document.getElementById("result2").innerHTML=sessionStorage.pagecount; //获取 </script> </body> </html>