Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我尝试使用 jquery 中的 cookie 插件来做到这一点
$.cookie('XXX', 'the_value', 22); alert($.cookie('XXX'));
但是警报输出为空(我在本地尝试过)
为什么?
插件在那里:https ://github.com/carhartl/jquery-cookie/
您需要设置过期时间:
$.cookie('XXX', 'the_value', { expires: 22 });
阅读这篇文章:
$.cookie("example", "foo");
这是为当前路径级别设置的会话 cookie,将在用户退出浏览器时销毁。要使相同的 cookie 持续例如 7 天,请执行以下操作:
$.cookie("example", "foo", { expires: 7 });