【问题标题】:how can we remove cookies on all pages on logout in jquery?我们如何在 jquery 注销时删除所有页面上的 cookie?
【发布时间】:2012-12-06 19:27:23
【问题描述】:

嘿,我是 jquery 的新手,并且将 mvc3 与 jquery 一起使用。 谁能告诉我如何在使用 jquery 单击注销按钮时清除我们网站上所有页面上的 cookie?

在登录按钮上,我的代码是:

$('.login').click(function(){
    var username = $('#uname').val();
    var password = $('#upass').val();

    $.cookie('username', username, { path: '/' });
    $.cookie('password', password, { path: '/' });
});

我想用 jquery 清除一行代码中的所有 cookie。谁能建议我,我该怎么做????

【问题讨论】:

  • 请在发布问题之前彻底搜索。 @alliswell 干得好。
  • @alliswell 此代码清除其文档(创建它的特定页面)的 cookie,但我想从所有页面中删除这些 cookie。

标签: jquery jquery-cookie


【解决方案1】:

要使用 JQuery 删除 cookie,请将值设置为 null:

$.cookie('username', null);
$.cookie('password', null);

【讨论】:

  • 嘿,但我想用一行代码删除两个 cookie。我该怎么做?
  • @Parasignals 你必须删除 字符
猜你喜欢
  • 1970-01-01
  • 2013-10-26
  • 2012-10-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-12
  • 2016-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多