zoukankan      html  css  js  c++  java
  • js 设置cookie转

    原文地址: http://www.cnblogs.com/wwcherish/archive/2013/04/17/3026848.html

    <script type="text/javascript">
            function Get_Cookie(name) {
                var start = document.cookie.indexOf(name + "=");
                var len = start + name.length + 1;
                if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
                if (start == -1) return null;
                var end = document.cookie.indexOf(";", len);
                if (end == -1) end = document.cookie.length;
                return decodeURI(document.cookie.substring(len, end));
            }

            function Set_Cookie(name, value, expires, path, domain, secure) {
                expires = expires * 60 * 60 * 24 * 1000;
                var today = new Date();
                var expires_date = new Date(today.getTime() + (expires));
                var cookieString = name + "=" + decodeURIComponent(value)/** encodeURIComponent(value) 貌似也行**/ +
                     ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
                     ((path) ? ";path=" + path : "") +
                     ((domain) ? ";domain=" + domain : "") +
                     ((secure) ? ";secure" : "");
                document.cookie = cookieString;
            }

            //页面加载
            $(function () {

                Set_Cookie('dynewform_name', 'zhuname', 36500);
                var nameone = Get_Cookie("dynewform_name");
               
                 alert(nameone)  //==>zhuname
            });
        </script>

  • 相关阅读:
    纪中第三天
    纪中第一天
    图片验证码的实现
    使用监听器解决路径问题
    log4j测试示例
    redis示例
    kafka示例
    CSRF verification failed. Request aborted.
    TemplateDoesNotExist
    创建 django 项目命令
  • 原文地址:https://www.cnblogs.com/ry123/p/3040904.html
Copyright © 2011-2022 走看看