首页 > 代码库 > cookie&&localstorage

cookie&&localstorage

设置cookie

document.cookie = ‘name = getCookie‘;

设置cookie过期时间

document.cookie= ‘name = getCookie;expires =‘+ new Date(new Date().setTime(new Date().getTime()*5000)).toGTMString();

设置localstorage

localStorage.setItem("key", "value");

获取localstorage

localStorage.getItem(‘key‘);

删除localstorage

localStorage.removeItem(‘key‘);

清楚所有的key和value值

localStorage.clear();

 

cookie&&localstorage