jquery.cookie插件官方下载地址与使用方法 - webxzy

时间:2024-03-17 18:32:07

jquery.cookie插件官方下载地址与使用方法

下载地址:https://github.com/carhartl/jquery-cookie

jquery.cookie使用方法:

创建 临时cookie:

$.cookie(\'name\', \'value\');

创建有效时间期限为7天的 cookie:

$.cookie(\'name\', \'value\', { expires: 7 });

创建有效期限为7天并带路径的 cookie:

$.cookie(\'name\', \'value\', { expires: 7, path: \'/\' });

读取 cookie:

$.cookie(\'name\'); // => "value"
$.cookie(\'nothing\'); // => undefined

读取浏览器中所有的 cookies:

$.cookie(); // => { "name": "value" }

删除 cookie:

// Returns true when cookie was successfully deleted, otherwise false
$.removeCookie(\'name\'); // => true
$.removeCookie(\'nothing\'); // => false

// Need to use the same attributes (path, domain) as what the cookie was written with
$.cookie(\'name\', \'value\', { path: \'/\' });
// This won\'t work!
$.removeCookie(\'name\'); // => false
// This will work!
$.removeCookie(\'name\', { path: \'/\' }); // => true

Note: when deleting a cookie, you must pass the exact same path, domain and secure options that were used to set the cookie, unless you\'re relying on the default options that is. 这段话自己翻译