如何使用jquery(或只是javascript)迭代cookie? [英] How can I iterate over cookies using jquery (or just javascript)?

查看:141
本文介绍了如何使用jquery(或只是javascript)迭代cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Klaus Hartl的Cookie插件添加或更新Cookie $(document).ready 。我有另一个事件,它应该迭代所有的cookie,并做一些与每个cookie的值。如何迭代cookie的集合,并获取每个的id和值?

I am using the "Cookie Plugin" by Klaus Hartl to add or update cookies at $(document).ready. I have another event that is supposed to iterate all the cookies and do something with the value of each cookie. How can I iterate over the collection of cookies and get the id and value of each?

我想像这样:

$.cookie.each(function(id, value) { 
            alert('ID='+id+' VAL='+value); 
        });


推荐答案

如果您只想查看Cookie,这个没有额外的插件:

If you just want to look at the cookies it's not that hard without an extra plugin:

$.each(document.cookie.split(/; */), function()  {
  var splitCookie = this.split('=');
  // name is splitCookie[0], value is splitCookie[1]
});

这篇关于如何使用jquery(或只是javascript)迭代cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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