zoukankan      html  css  js  c++  java
  • JS操作Cookie

    <script type="text/javascript" language="javascript">
        //写入cookie
        function setCookie(name, value) {
            var days = 30;
            var exp = new Date();
            exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
        }
        //读取cookie
        function getCookie(name) {
            var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
            if (arr != null)
                return unescape(arr[2]);
            return null;
        }
        //删除cookie
        function delCookie(name) {
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);
            var cval = getCookie(name);
            if (cval != null)
                document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
        }
        //获取cookie解码后的值
        function getCookieValue(offset) {
            var endstr = document.cookie.indexOf(";", offect);
            if (endsrt == -1) {
                endstr = document.cookie.length;
            }
            return unsecape(document.cookie.substring(offset, endstr));
        }

        function test() {
            setCookie("testName", "testContent")
            alert(getCookie("testName"));
        }
    </script>

    <input type="button" value="test" onclick="test();" />

  • 相关阅读:
    YUM软件管理
    RPM软件包管理
    Linux系统启动详解
    Linux命令行文本处理工具
    Linux多命令协作:管道及重定向
    Linux网络基础配置
    网络基础
    Linux扩展权限
    Linux权限机制
    Linux用户基础
  • 原文地址:https://www.cnblogs.com/dachie/p/1791104.html
Copyright © 2011-2022 走看看