-1

On my project i have a mysql query which select some results from my mysql table.So the problem is,for each result i display a button,when the user clicks on those button i need to store the result id in cookies,but every time i tried to make it work always the value stored on cookies is always from the first record!How can i make the value stored become the one from the chosen result?

4

1 回答 1

-1

Cookie 只能存储字符串。它不能存储数组。在使用以下函数存储之前,使用 javascript join 将其转换为“,”分隔值 -

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
于 2012-04-15T06:27:37.527 回答