jQuery插件之jquery-cookie
使用carhartl编写的jquery-cookie可以方便的设置cookie。具体用法如下:
下载
https://github.com/carhartl/jquery-cookie
安装
放在jquery库的后面:
<script src="/path/to/jquery.cookie.js"></script>
用法
新建cookie:
$.cookie('the_cookie', 'the_value');
设定有效期7天,作用于整个站点:
$.cookie('the_cookie', 'the_value', { expires: 7,path: "/" });
读取cookie:
$.cookie('the_cookie'); // => "the_value" $.cookie('not_existing'); // => null
删除cookie:
// Returns true when cookie was found, false when no cookie was found... $.removeCookie('the_cookie'); // Same path as when the cookie was written... $.removeCookie('the_cookie', { path: '/' });