zoukankan      html  css  js  c++  java
  • cookie的设置和获取

    // 创建cookie
    function setCookie(name, value, expires, path, domain, secure) {
    var cookieText = encodeURIComponent(name) + '=' + encodeURIComponent(value);
    if (expires instanceof Date) {
    cookieText += '; expires=' + expires;
    }
    if (path) {
    cookieText += '; expires=' + expires;
    }
    if (domain) {
    cookieText += '; domain=' + domain;
    }
    if (secure) {
    cookieText += '; secure';
    }
    document.cookie = cookieText;
    }
    // 获取cookie
    function getCookie(name) {
    var cookieName = encodeURIComponent(name) + '=';
    var cookieStart = document.cookie.indexOf(cookieName);
    var cookieValue = null;
    if (cookieStart > -1) {
    var cookieEnd = document.cookie.indexOf(';', cookieStart);
    if (cookieEnd == -1) {
    cookieEnd = document.cookie.length;
    }
    cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
    }
    return cookieValue;
    }
    // 删除cookie
    function unsetCookie(name) {
    document.cookie = name + "= ; expires=" + new Date(0);
    }

  • 相关阅读:
    Linux makefile
    java泛型
    Java中Split函数的用法技巧
    mysql基础笔记
    Linux学习路线浅谈
    泛型的用法
    数据流图的画法
    oracle学习路线图
    c++学习建议
    C#学习建议
  • 原文地址:https://www.cnblogs.com/bluesky1024/p/6503285.html
Copyright © 2011-2022 走看看