Cookie名称以预定义值开头

时间:2011-08-09 21:02:24

标签: php javascript cookies

我正在使用javascript创建Cookie,其Cookie名称以SC_

开头

例如,以下是一些cookie名称(可能有数百个这样的cookie):

  • SC_item1
  • SC_hello
  • SC_23
  • SC_a
  • SC_B

现在我想要读取/搜索以前缀SC_开头的所有Cookie(在Javascript中)。我怎么能这样做?

以下是我用来创建Cookie的代码;

function addToCart(itemid, quantity)
{
    var cookieName = "SC_"+itemid;
    var value = "hello world";
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + 365);
    var cookieValue= escape(value) + ((exdate==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie = cookieName + "=" + cookieValue;
}

0 个答案:

没有答案
相关问题