例如我生成了这样一个cookieResponse.Cookies["cz"].Value = "yyy";
Response.Cookies["cz"].Expires = DateTime.Now.AddDays(1);在js里怎么读取这个cz呢,要判断cz是否等于yyy,帮忙写一下,谢谢!

解决方案 »

  1.   

    可以参考我的博客
    http://blog.csdn.net/avon520/archive/2008/10/07/3029375.aspx
      

  2.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    </body>
    </html>
    <script>
    //创建一个可在 cookie 变量中存储访问者姓名的函数,expiredays:过期时间
    function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
    }
    //们要创建另一个函数来检查是否已设置 cookie
    function getCookie(c_name)
    {
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
        } 
      }
    return ""
    }
    //创建cookies
    setCookie("adonis","goodboy","10");
    //访问cookies
    var userinfo=getCookie("adonis");
    if(userinfo == "goodboy")
    {
    alert("OK");
    }
    </script>
      

  3.   

    读的时候读document.cookie,然后对document.cookie进行分析(split),历遍,
    范例:
    function GetCookie(sName) {//獲得Cookie
    var arg = sName + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return GetCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
    }
    return null;
    }