zoukankan      html  css  js  c++  java
  • js cookie

     js操作cookie的问题。

    做个标记

    /**//************************************************************************

    |    函数名称: setCookie                                                |
    |    函数功能: 设置cookie函数                                            |
    |    入口参数: name:cookie名称;value:cookie 值                        |
    |    维护记录: RainBow(创建)                                            |
    |    版权所有: (C) 2006-2007                    |
    |    编写时间: 2007年9月13 日 21:00                                        |
    *************************************************************************/
    function setCookie(name, value)
    {
        var argv = setCookie.arguments;
        var argc = setCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        if(expires!=null)
        {
            var LargeExpDate = new Date ();
            LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));         
        }
        document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString()))+"; path=" + "/";
    }
    /**//************************************************************************
    |    函数名称: getCookie                                                |
    |    函数功能: 读取cookie函数                                            |
    |    入口参数: Name:cookie名称                                            |
    |    维护记录: RainBow(创建)                                            |
    |    版权所有: (C) 2006-2007                    |
    |    编写时间: 2007年9月13 日 21:02                                        |
    *************************************************************************/
    function getCookie(Name)
    {
        var search = Name + "=" ;
        if(document.cookie.length > 0)
        {
            offset = document.cookie.indexOf(search)
            if(offset != -1)
            {
                offset += search.length
                end = document.cookie.indexOf(";", offset)
                if(end == -1) end = document.cookie.length
                return unescape(document.cookie.substring(offset, end))
            }
            else return "";
        }
    }

    /**//************************************************************************
    |    函数名称: deleteCookie                                            |
    |    函数功能: 删除cookie函数                                            |
    |    入口参数: Name:cookie名称                                        |
    |    维护记录: RainBow(创建)                                        |
    |    版权所有: (C) 2006-2007                 |
    |    编写时间: 2007年9月15 日 18:10                                    |
    *************************************************************************/    
    function delCookie(name)
    {
         var expdate = new Date();
         expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
         setCookie(name, "", expdate);
    }
  • 相关阅读:
    topsort模板,poj 2585
    CUG2012年暑期ACM训练赛(单人赛)
    第一个QT, "hello linux"
    AOE网络,最长路关键路径的学习
    种类位置信息:geometry
    标准对话框:StandardDialogs
    最近整理的模板
    单调队列的学习
    118 ZOJ Monthly, July 2012
    离散化 + unique + lower_bound的学习,hdu4325
  • 原文地址:https://www.cnblogs.com/youliny/p/1778329.html
Copyright © 2011-2022 走看看