首页 > 开发 > JS > 正文

jquery有没有方便cookie进行读写操作的方法

2017-09-05 13:02:23  来源:网友分享

如题,对cookie中的某些内容进行读取、设置和删除等方法?

解决方案

无官方支持,有插件实现。
比如:https://github.com/carhartl/jquery-co...

补充插件使用法

创建 cookie:

$.cookie('the_cookie', 'the_value');

创建有效期7天的 cookie:

$.cookie('the_cookie', 'the_value', { expires: 7 });

创建有效期7天的整站 cookie:

$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });
读取 cookie:

$.cookie('the_cookie'); // => "the_value"$.cookie('not_existing'); // => null

删除 cookie:

// cookie 存在是返回 true,否则返回 false$.removeCookie('the_cookie');// path 路径要和创建的时候一致$.removeCookie('the_cookie', { path: '/' });