zoukankan      html  css  js  c++  java
  • 通用js模块04:cookieUtils.js

    /* ===========================================================
    模块说明:对于cookie操作的一些补充功能
    charset:gb2312
    调用模块:
    搜集整理:sagahu@163.com
    最后修订:2013-01-22
    */

    function addCookie(name, value, expireDays, path, domain) {
        delCookie(name);
        expireDays = expireDays ? expireDays : 30;
        path = path ? path : "/";
        var date = new Date();
        date.setTime(date.getTime() + expireDays * 24 * 60 * 60 * 1000);
        var str = name + '=' + escape(value) + ';expires=' + date.toGMTString();
        if (path) str += ';path=' + path;
        if (domain) str += ';domain=' + domain;
        document.cookie = str;
    }

    function getCookie(name) {
        var arr = document.cookie.split(';');
        for (var i = 0; i < arr.length; i++) {
            var arr2 = arr[i].split('=');
            if (arr2[0] == name)
                return unescape(arr2[1]);
        }
        return null;
    }

    function delCookie(name) {
        var date = new Date();
        date.setTime(date.getTime() - 10000);
        document.cookie = name + "=; expires=" + date.toGMTString();
    }

    function getCookie2(name, defaultValue, expireDays, path, domain) {
        var ret = getCookie(name);
        if (!ret) {
            ret = defaultValue;
            addCookie(name, ret, expireDays, path, domain);
        }
        return ret;
    }

  • 相关阅读:
    java-日期转换
    java-Timestamp
    java-判断年份是不是闰年
    Java中Date与String的相互转换
    ORA-01830
    js数组合并
    js清空子节点
    私钥密码
    图片基本样式
    XMLHttpRequest: 网络错误 0x2ee4, 由于出现错误 00002ee4 而导致此项操作无法完成
  • 原文地址:https://www.cnblogs.com/sagahu/p/2710031.html
Copyright © 2011-2022 走看看