以简单的方式设置/取消设置cookie jquery-cookie

时间:2015-07-27 16:12:12

标签: jquery html cookies

我有一个显示/隐藏onClick事件div的按钮。我想记住状态,点击保持div隐藏一天(设置cookie过期)和另一次点击保持div显示(删除cookie)。

我需要记住整个领域的这种状态。

最简单的方法是什么? 我是初学者,我更喜欢jquery-cookie - 它可以使用吗? 我找不到任何关于onClick事件解释的例子。

非常感谢!

2 个答案:

答案 0 :(得分:0)

查看jquery-cookie插件。

文档只是here

以下是jsfiddle中有关如何使用它的示例(设置cookie /未设置cookie /显示cookie):http://jsfiddle.net/rdtome/73vzD/239/

(见行):

$.cookie('test_cookie', 'hello cookie !'); // SET cookie
$.removeCookie('test_cookie'); // DELETE cookie
$.cookie('test_cookie'); // GET cookie

答案 1 :(得分:0)

请找到更好方式Cookie管理的网址。 Create, read, and erase cookies with jQuery

OR

for set cookie:
    $.cookie('cookieName', 'value', { expires: 7 });
for read cookie:
    $.cookie('the_cookie');

for Delete cookie:// set nulll for delete
    $.cookie('the_cookie', null);

了解更多信息。 http://www.jquerybyexample.net/2012/06/jquery-cookies-get-set-and-delete.html

相关问题