zoukankan      html  css  js  c++  java
  • cookie函数

    function getcookie(){
    var cookie={};
    var all=document.cookie;
    if(all===""){ alert(2);
    return cookie;
    }
    var list=all.split("; ");
    for(var i=0;i<list.length;i++){
    var cookie=list[i];
    var p=cookie.indexOf("="); //返回位置
    var name=cookie.substring(0,p);
    var value=cookie.substring(p+1);
    cookie[name]=value;
    console.dir(cookie);
    } alert(1);
    return cookie;
    }
    getcookie();

    /**
    * 设置cookie
    * @param {String} name
    * @param {String} value
    * @param {String} expires
    * @param {String} path
    * @param {String} domain
    * @param {String} secure
    */
    function $setCookie(name, value, expires, path, domain, secure) {
    var exp = new Date(), expires = arguments[2] || null, path = arguments[3] || "/", domain = arguments[4] || null, secure = arguments[5] || false;
    expires ? exp.setMinutes(exp.getMinutes() + parseInt(expires)) : "";
    document.cookie = name + '=' + escape(value) + ( expires ? ';expires=' + exp.toGMTString() : '') + ( path ? ';path=' + path : '') + ( domain ? ';domain=' + domain : '') + ( secure ? ';secure' : '');
    }

    /* --------------------------------------------------
    * 获取cookie
    * @param {string} name
    * @return null 没有找到
    * @return ""/string value
    */
    function $getCookie(name) {
    var reg = new RegExp("(^| |(?=;))" + name + "(?:=([^;]*))?(;|$)"), val = document.cookie.match(reg);
    return val ? (val[2] ? unescape(val[2]) : "") : null;
    }

    /*
    * 删除cookie
    * @param {String} name
    * @param {String} path
    * @param {String} domain
    * @param {String} secure
    */
    function $delCookie(name, path, domain, secure) {
    var value = $getCookie(name);
    if (value != null) {
    var exp = new Date();
    exp.setMinutes(exp.getMinutes() - 1000);
    path = path || "/";
    document.cookie = name + '=;expires=' + exp.toGMTString() + ( path ? ';path=' + path : '') + ( domain ? ';domain=' + domain : '') + ( secure ? ';secure' : '');
    }
    }

  • 相关阅读:
    Vim 使用设置
    stm32之CAN发送、接收详解
    stm32内部的CAN总线
    stm32之CAN总线基础
    JavaScript之Ajax
    JavaScript之insertBefore()和自定义insertAfter()的用法。
    JavaScript之向文档中添加元素和内容的方法
    JavaScript之共享onload
    JavaScrtip之JS最佳实践
    XX秘籍
  • 原文地址:https://www.cnblogs.com/rainbow661314/p/3336567.html
Copyright © 2011-2022 走看看