引用
下载与引入:jquery.cookie.js基于jquery;先引入jquery,再引入:jquery.cookie.js;下载:http://plugins.jquery.com/cookie/
<script src="js/jquery.min.js></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
添加cookie
$.cookie('the_cookie', 'the_value', { expires: 7 });
$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
//这里指明了cookie有效时间,所创建的cookie被称为“持久 cookie (persistent cookie)”。注意单位是:天;
//在默认情况下,只有设置 cookie的网页才能读取该 cookie。
//如果想让一个页面读取另一个页面设置的cookie,必须设置cookie的路径。cookie的路径用于设置能够读取 cookie的顶级目录。
//将这个路径设置为网站的根目录,可以让所有网页都能互相读取 cookie (一般不要这样设置,防止出现冲突)。
读取cookie
$.cookie('the_cookie');
删除cookie
$.cookie('the_cookie', null); //通过传递null作为cookie的值
可选参数
$.cookie('the_cookie','the_value',{
expires:7,
path:'/',
domain:'jquery.com',//创建cookie的页面域名
secure:true//如果为true,那么此cookie的传输会要求一个安全协议,例如https
})
web storage
//介绍
localstorage 是一种没有时间限制的数据存储方式
sessionstorage 是一种会话级别的存储。
//操作
localstorage.setItem('fang',18);// 设置
localstorage.removeItem('fang');//删除
本文暂时没有评论,来添加一个吧(●'◡'●)