最新jQuery Cookie Plugin & 中文文档

链接https://github.com/carhartl/jquery-cookie

20141121232416

使用方法简介:

创建 session cookie(浏览器关闭后删除):

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

 

创建指定过期时间的cookie,7天后过期:

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


创建7天后会过期的cookie,cookie对整个网站有效:

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


读取cookie

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


读取所有cookie:

$.cookie(); // => { "the_cookie": "the_value", "...remaining": "cookies" }


删除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: '/' });