标签:reg sub nes tick class exist domain mat doc
1.判断cookie存不存在
var existence = document.cookie.indexOf(‘ticket=‘); if(existence > -1){//存在 } else if(existence == -1){ //不存在 }
2.设置cookie
kk_main.setCooKie = function(name,value,expiredays){ var doMain = kk_main.WEB_URL.substring(kk_main.WEB_URL.indexOf(‘.‘)); var exp = new Date(); exp.setTime(exp.getTime() + expiredays*24*60*60*1000); document.cookie = name + "="+ value + ";expires=" + exp.toGMTString()+";path=/;Domain="+ doMain; }
3.获取cookie
kk_main.getCookie = function(name){ var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); if(arr=document.cookie.match(reg)) return unescape(arr[2]); else return null; }
标签:reg sub nes tick class exist domain mat doc
原文地址:http://www.cnblogs.com/daixiaotian/p/6402359.html