• 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');
  • 相关阅读:
    Save the problem!
    Divisiblity of Differences
    定个小目标
    Faulty Robot
    反片语 uva 156(map的使用
    Input is terminated by EOF.
    uva10815 andy的字典(set的应用)
    uva-101 搬砖问题(不定长数组vector的使用)
    回文串uva401(清简出风尘)
    WERTYU (善用常量数组
  • 原文地址:https://www.cnblogs.com/sunmyboke/p/7373541.html
Copyright © 2020-2023  润新知