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

使用方法:

设置 cookie:

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

注:如果 $.cookie 没有第三个参数,那么当浏览器关闭时,该 cookie 将会自动删除。

设置一个有效期为 7 天的 cookie:

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

注:$.cookie 第三个参数是一个对象,除了可以设置有效期(expires: 7),还可以设置有效路径(path: '/')、有效域(domain: 'jquery.com')及安全性(secure: true)。

读取 cookie:

$.cookie('the_cookie');

注:如果没有该 cookie,返回 null。

删除 cookie:

$.cookie('the_cookie', null);

我们只需要给需要删除的 cookie 设置为 null,就可以删除该 cookie。


相关文章:

  • 2022-12-23
  • 2021-06-27
  • 2021-10-21
  • 2022-12-23
  • 2022-02-09
  • 2021-12-18
  • 2021-06-07
猜你喜欢
  • 2021-05-22
  • 2021-08-28
  • 2021-08-30
  • 2021-12-28
  • 2021-08-15
  • 2022-12-23
相关资源
相似解决方案