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);
    }
  • 相关阅读:
    Convert.ToInt32()和int.Parse()的区别
    C# 提取字符串中的数字
    asp.net FileUpload 控件上传文件 以二进制的形式存入数据库并将图片显示出来
    angularjs如何在ng-repeat过程中控制字符串长度超过指定长度后面内容以省略号显示
    html label 标签的 for 属性
    bootstrap-paginator 分页控件的使用
    时间戳的转换
    Server.MapPath() 解析
    Angularjs 日期格式转换
    1.docker 慕课入门
  • 原文地址:https://www.cnblogs.com/youliny/p/1778329.html
Copyright © 2011-2022 走看看