如何删除所有的cookie与jquery [英] How to delete all cookies with jquery

查看:195
本文介绍了如何删除所有的cookie与jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

使用javascript清除所有Cookie

一个复选框被分配来激活和清除以前存储在我的表单中的所有cookie一次。我如何做到这一点与jquery cookie插件?我不能在Klaus网站和这里找到例子。

I would like to have a checkbox assigned to activate and wipe out all cookies previously stored in my forms in one go. How would I do that with jquery cookie plugin? I can't seem to find examples in Klaus site and here.

任何提示都将非常感激。

Any hint would be very much appreciated.

感谢

推荐答案

这个问题应该可以完成你所期望的:

The accepted answer in this question should accomplish what you're after:

var cookies = document.cookie.split(";");
for(var i=0; i < cookies.length; i++) {
    var equals = cookies[i].indexOf("=");
    var name = equals > -1 ? cookies[i].substr(0, equals) : cookies[i];
    document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}

(为了清晰起见,链接的答案扩展了代码,无需重新wheel这里)

(code is expanded for clarity from the linked answer, no need to reinvent the wheel here)

在所有情况下都不需要插件,有时一个简单的JavaScript代码段会做... jQuery真的不帮助这里

There's no need for a plugin in all cases, sometimes a simple JavaScript snippet will do...jQuery really doesn't help at all here

这篇关于如何删除所有的cookie与jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆