• cookie的使用


     1 function Cookie() {};
     2     Cookie.prototype = {
     3         constructor: Cookie,
     4         _path: "/",
     5         expire: new Date(),
     6         setPath: function(path) {
     7             this._path = !path ? this._path : path;
     8         },
     9         getPath: function() {
    10             return this._path;
    11         },
    12         set: function(name, value, day) {
    13             if (this.get(name)) this.del(name);
    14             day = day ? day : 0;
    15             this.expire.setTime(this.expire.getTime() + day * 24 * 3600 * 1000);
    16             document.cookie = name + "=" + escape(value) + (day != 0 ? ";expires=" + this.expire.toGMTString() : "") + ";path=" + this.getPath();
    17         },
    18         get: function(name) {
    19             var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    20             if (arr != null) {
    21                 return unescape(arr[2]);
    22             }
    23         },
    24         del: function(name) {
    25             if (this.get(name)) {
    26                 document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT;path=" + this.getPath();
    27             }
    28         },
    29         delAll: function() {
    30             var arr = document.cookie.match(/[^ =;]+(?==)/g);
    31             if (arr) {
    32                 for (var i = arr.length; i--;) {
    33                     this.del(arr[i]);
    34                 }
    35             }
    36         }
    37     };
    38     var cookie = new Cookie();
    39     cookie.set('flag', 'audit');
  • 相关阅读:
    HDU
    android 博客园
    android105 jni概念
    android104 帧动画,补间动画,属性动画
    requestFocusFromTouch , requestFocus
    android103 内容观察者
    android102 查询,插入联系人
    android101 获取、备份、插入短信
    android100 自定义内容提供者
    android99 拍照摄像
  • 原文地址:https://www.cnblogs.com/sunmyboke/p/7373541.html
Copyright © 2020-2023  润新知