getcookies
setcookiesThis example creates a cookie with a specified name and value. The value is passed to the JScript escape function to ensure that the value only contains valid characters. When the cookie is retrieved, the JScript unescape function should be used to translate the value back to its original form.<SCRIPT>
// Create a cookie with the specified name and value.
// The cookie expires at the end of the 20th century.
function SetCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + "; 
  expires=Mon, 31 Dec 1999 23:59:59 UTC;";
}
</SCRIPT>
This example retrieves the value of the portion of the cookie specified by the sCookie parameter.<SCRIPT>
// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }  // a cookie with the requested name does not exist
  return null;
}
</SCRIPT>

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/685/685109.xml?temp=.6255609
      

  2.   

    在js中要读取某个cookie的值不能像在ASP中直接引用cookie的名字就可以读取,自己写一个函数吧,例子://读取Cookie
    //name:要读取的Cookie的名字
    function getCookie (name) {
    var presence =document.cookie.indexOf(name);
    if (presence != -1) {
    var start = presence + name.length + 1;
    var end = document.cookie.indexOf(";", start);
    if (end == -1)
    end = document.cookie.length;
    var value = document.cookie.slice(start, end);
    return unescape(value);
    }
    else return false;
    }