zoukankan      html  css  js  c++  java
  • cookie

    function addCookie(name, value, expireHours) {
        var cookieString = name + "=" + (typeof value == 'string' ?  decodeURI(value.replace(/+/g, '%2B')) : value) + "; path=/";
        //判断是否设置过期时间
        if (expireHours > 0) {
            var date = new Date();
            date.setTime(date.getTime() + expireHours * 3600 * 1000);
            cookieString = cookieString + ";expires=" + date.toGMTString();
        }
        document.cookie = cookieString;
    }
    
    function getCookie(name) {
        var strcookie = document.cookie;
        var arrcookie = strcookie.split("; ");
        for (var i = 0; i < arrcookie.length; i++) {
            var arr = arrcookie[i].split("=");
            if (arr[0] == name){
                return unescape(arr[1]); 
            }
        }
        return null;
    }
    
    function delCookie(name) {//删除cookie
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null)
            document.cookie = name + "=" + cval + "; path=/;expires=" + exp.toGMTString();
    }
  • 相关阅读:
    eclipse
    ORA00904:标识符无效,preparedstatement
    mysql 创建用户
    web 默认servlet
    https tomat
    gzip
    sftp 上传文件
    jquery dwrutil confilit
    xmlbeans读写xml文件
    敏捷开发“松结对编程”实践大型团队篇
  • 原文地址:https://www.cnblogs.com/theWayToAce/p/7485083.html
Copyright © 2011-2022 走看看