js设置cookie,获取cookie值及删除cookie值代码

时间:2013-05-05 04:10:07  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:ar exp = new Date();        exp.setTime (exp.getTime()+3600000000);        document.cookie = name + "=" + value + "; expires=" + exp.toGMTString()+"; path=/"; } function getCookieVal (offset) {  var endstr = document.cookie.indexO...
  正文:js(第二电脑网http://www.002pc.com)设置cookie,获取cookie值及删除cookie值代码

js(第二电脑网http://www.002pc.com)设置cookie,获取cookie值及删除cookie值代码
function SetCookie (name, value) {
       var exp = new Date();
       exp.setTime (exp.getTime()+3600000000);
       document.cookie = name + "=" + value + "; expires=" + exp.toGMTString()+"; path=/";
}

function getCookieVal (offset) {
 var endstr = document.cookie.indexOf (";", offset);
 if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
 }
function DelCookie(name)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

function GetCookie(name) {
         var arg = name + "=";
         var alen = arg.length;
         var clen = document.cookie.length;
         var i = 0;
         while (i < clen) {
             var j = i + alen;
             if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
             i = document.cookie.indexOf(" ", i) + 1;
             if (i == 0) break;
         }
      return null;
 }


js设置cookie,获取cookie值及删除cookie值代码》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/JavaScript/25482.html


关于《js设置cookie,获取cookie值及删除cookie值代码》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td