1

嗨,我尝试使用 jquery 中的 cookie 插件来做到这一点

$.cookie('XXX', 'the_value', 22);
alert($.cookie('XXX'));

但是警报输出为空(我在本地尝试过)

为什么?

插件在那里:https ://github.com/carhartl/jquery-cookie/

4

1 回答 1

1

您需要设置过期时间:

$.cookie('XXX', 'the_value', { expires: 22 });

阅读这篇文章

$.cookie("example", "foo");

这是为当前路径级别设置的会话 cookie,将在用户退出浏览器时销毁。要使相同的 cookie 持续例如 7 天,请执行以下操作:

$.cookie("example", "foo", { expires: 7 });
于 2012-06-25T22:29:55.083 回答