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();" />

  • 相关阅读:
    java实现微信红包分配算法
    认识J2SE
    java设计模式(2)
    java设计模式(1)
    模拟做饭系统(java+线程中的join方法)
    学习接水系统(java+thread线程)
    1. linux系统简介
    Codeforces Round #350 (Div. 2)解题报告
    2014蓝桥杯决赛解题报告
    末学者笔记--Python函数一玄
  • 原文地址:https://www.cnblogs.com/dachie/p/1791104.html
Copyright © 2011-2022 走看看