销毁jquery cookie

时间:2012-09-27 08:31:53

标签: jquery json cookies append

我有一个脚本,允许将输入值保存为列表:JsFiddle

所以现在我试图制作一个事件,如果点击就会删除某个列表,当然cookie应该被销毁。所以我试过了:

$('.jq-text li').click(function(e) {

$.cookie("myDemoCookie", null);

 });

这应该会破坏cookie,但它不会......

1 个答案:

答案 0 :(得分:1)

我看到了您的jsfiddle代码,您正在使用路径创建Cookie,因此在删除Cookie时您必须指定path

确保您已阅读documentation of $.cookie

@example $.cookie('the_cookie', null);

@desc Delete a cookie by passing null as value. 
 Keep in mind that you have to use the same path 
 and domain used when the cookie was set.`

请尝试以下代码:

$.cookie('myDemoCookie', null, { path: '/' });