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

    /*cookie的三种操作:读取,写入,删除*/
    var CookieUtil = {
      get:function(name){
        var cookieName = encodeURIComponent(name) + "=",
            cookieStart = document.cookie.indexOf(cookieName),
            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;
      },
      set:function(name,value,expires,path,domain,secure){
        var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
        if (expires instanceof Date) {
          cookieText += ";expires=" + expires.toGMTString();
        }
        if (path) {
          cookieText += ";path=" + path;
        }
        if (domain) {
          cookieText += ";domain=" + domain;
        }
        if (secure) {
          cookieText += ";secure";
        }
        document.cookie = cookieText;
      },
      unset:function(name,path,domain,secure){
        this.set(name,"",new Date(0),path,domain,secure);
      }
    };
  • 相关阅读:
    学习进度
    作业8:单元测试练习
    用户体验设计案例分析
    团队协作一
    需求分析
    结对编程——词频统计 2
    结对编程——词频统计
    个人项目-词频统计
    数组求和
    个人介绍和Github使用流程
  • 原文地址:https://www.cnblogs.com/login123/p/12243503.html
Copyright © 2011-2022 走看看