<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> /*if(a==0){localStorage.setItem("key","0");}//以“key”为名称存储一个值“value” a = localStorage.getItem("key");*/ //获取名称为“key”的值 // localStorage.removeItem("key");//删除名称为“key”的信息。 // localStorage.clear();//清空localStorage中所有信息 if(!localStorage.getItem("key")){ a = 0; localStorage.setItem("key","0"); }else{ a = localStorage.getItem("key"); localStorage.setItem("key",++a); } document.write(a); // localStorage.clear(); /*上面这是一种方法*/ /*下面也是一种方法,pagecount是localStorage的一个自带属性*/ if (localStorage.pagecount) { localStorage.pagecount=Number(localStorage.pagecount) +1; } else { localStorage.pagecount=1; } document.write("Visits "+ localStorage.pagecount + " time(s)."); </script> </body> </html>