摘要:[javascript] //写Cookie参数:CKname是cookie名称(必填),CKvalue是cookie值(必填),duration是过期时间(默认为关闭浏览器),CKpath是可访问cookie的目录(默认为所有页面),CKdomain是可访问cookie的主机名(默认为当前域名下[子域名]);   function setCookie(CKname,CKvalue,duration,CKpath,CKdomain){      var NewDate = new Date();      NewDate.setTime(NewDate.getTime()+duration*24*60*60*1000);      document.cookie = CKname+"="+escape(CKvalue)+(duration?";expires="+NewDate.toGMTString():"")+(CKpath?";path="+CKpath:"")+(CKdomain?";domain="+CKdomain:"");  };  //读取指定名称的cookie   function getcookie(CKname){      var arrCookie = document.cookie.match(new RegExp("(^| )"+CKname+"=([^;]*)(;|$)"));      if(arrCookie!=null){          return unescape(arrCookie[2]);      }else{          return null;      };  };  //删除指定名称的cookie   function deleteCookie(CKname){      document.cookie = CKname+"=;expires="+(new Date(0)).toGMTString();  }; 

小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

[javascript]
//写Cookie参数:CKname是cookie名称(必填),CKvalue是cookie值(必填),duration是过期时间(默认为关闭浏览器),CKpath是可访问cookie的目录(默认为所有页面),CKdomain是可访问cookie的主机名(默认为当前域名下[子域名]);  
function setCookie(CKname,CKvalue,duration,CKpath,CKdomain){ 
    var NewDate = new Date(); 
    NewDate.setTime(NewDate.getTime()+duration*24*60*60*1000); 
    document.cookie = CKname+"="+escape(CKvalue)+(duration?";expires="+NewDate.toGMTString():"")+(CKpath?";path="+CKpath:"")+(CKdomain?";domain="+CKdomain:""); 
}; 
//读取指定名称的cookie  
function getcookie(CKname){ 
    var arrCookie = document.cookie.match(new RegExp("(^| )"+CKname+"=([^;]*)(;|$)")); 
    if(arrCookie!=null){ 
        return unescape(arrCookie[2]); 
    }else{ 
        return null; 
    }; 
}; 
//删除指定名称的cookie  
function deleteCookie(CKname){ 
    document.cookie = CKname+"=;expires="+(new Date(0)).toGMTString(); 
}; 

//写Cookie参数:CKname是cookie名称(必填),CKvalue是cookie值(必填),duration是过期时间(默认为关闭浏览器),CKpath是可访问cookie的目录(默认为所有页面),CKdomain是可访问cookie的主机名(默认为当前域名下[子域名]);
function setCookie(CKname,CKvalue,duration,CKpath,CKdomain){
 var NewDate = new Date();
 NewDate.setTime(NewDate.getTime()+duration*24*60*60*1000);
 document.cookie = CKname+"="+escape(CKvalue)+(duration?";expires="+NewDate.toGMTString():"")+(CKpath?";path="+CKpath:"")+(CKdomain?";domain="+CKdomain:"");
};
//读取指定名称的cookie
function getcookie(CKname){
 var arrCookie = document.cookie.match(new RegExp("(^| )"+CKname+"=([^;]*)(;|$)"));
 if(arrCookie!=null){
  return unescape(arrCookie[2]);
 }else{
  return null;
 };
};
//删除指定名称的cookie
function deleteCookie(CKname){
 document.cookie = CKname+"=;expires="+(new Date(0)).toGMTString();
};

 

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

本文固定链接: http://www.js-code.com/js/js_8820.html