zoukankan      html  css  js  c++  java
  • js中的cookie的设置

     1 function SetCookie(name, value) {
     2     var exp = new Date();
     3     exp.setTime(exp.getTime() + 3600000000); //设置他的过期的时间
     4     document.cookie = name + "=" + value + "; expires=" + exp.toGMTString() + "; path=/";
     5 }
     6 function getCookieval_r(offset) {
     7     var endstr = document.cookie.indexOf(";", offset);
     8     if (endstr == -1) endstr = document.cookie.length;
     9     return unescape(document.cookie.substring(offset, endstr));
    10 }
    11 function DelCookie(name) {
    12     var exp = new Date();
    13     exp.setTime(exp.getTime() - 1);
    14     var cval = GetCookie(name);
    15     document.cookie = name + "=" + '' + "; expires=" + exp.toGMTString() + "; path=/"; 如果想要删除要和设置的时候的路径完全一致
    16    
    17 }
    18 function GetCookie(name) {
    19     var arg = name + "=";
    20     var alen = arg.length;
    21     var clen = document.cookie.length;
    22     var i = 0;
    23     while (i < clen) {
    24         var j = i + alen;
    25         if (document.cookie.substring(i, j) == arg) return getCookieval_r(j);
    26         i = document.cookie.indexOf(" ", i) + 1;
    27         if (i == 0) break;
    28     }
    29     
    30     return null;
    31 }
  • 相关阅读:
    训练1-J
    训练1-K
    训练1-P
    二分查找法详解
    POJ:1094-Sorting It All Out(拓扑排序经典题型)
    POJ:2632-Crashing Robots
    POJ:1086-Parencodings
    POJ:2586-Y2K Accounting Bug
    POJ:2109-Power of Cryptography(关于double的误差)
    POJ:1328-Radar Installation
  • 原文地址:https://www.cnblogs.com/jie123/p/4701301.html
Copyright © 2011-2022 走看看