JavaScript – localstorage

localStorage.setItem("lastname","smith"); //SET OR UPDATE
localStorage.getItem("lastname");  //GET
localStorage.lastname = "smith";  //SET OR UPDATE
localStorage.removeItem("lastname"); //REMOVE
localStorage.clear(); //REMOVE ALL
//expiry 做法
var hours = 24;
var now = new Date().getTime();
var setupTime = localStorage.getItem('setupTime');
if(setupTime == null){
  localStorage.setItem('setupTime', now);
}
else{
  if(now - setupTime > 1000 * 600){ //1000是ms, 600即是600秒(10分鐘)
    localStorage.clear();
    localStorage.setItem('setupTime', now);
  }
}

開始在上面輸入您的搜索詞,然後按回車進行搜索。按ESC取消。

返回頂部