标签:
/**
* Created by Administrator on 15-8-11.
*/
function setCookie(name,value,expires,path){
path=path==null?"/":path;//如果path没有赋值,则默认为本地根目录
var date=new Date();
date.setTime(date.getTime()+expires*1000);//得到当前时间到1970年1月1日的毫秒数//整体是未来事件
document.cookie=escape(name)+"="+escape(value)+";expires="+date.toUTCString()+";path="+path;
}
function delCookie(name,path) {
path=path==null?"/":path;
var date=new Date(1970,0,1);//直接设置为1970年1月1日的过去时间点
document.cookie=escape(name)+"=;expires="+date.toUTCString()+";path="+path;
}
function getCookie(name) {//查到name对应的值
var cookieAll=document.cookie;//得到所有cookie的值
if(cookieAll.length>0){
var start=cookieAll.indexOf(name);
if(start==-1){
return "不存在";
}
start=start+name.length+1;//得到值的首字符位置
var end=cookieAll.indexOf(";",start);//得到分号位置
if(end==-1){
return unescape(cookieAll.slice(start));//如果找不到分号,即最后一条cookie
}
else{
return unescape(cookieAll.slice(start,end));
}
}
else{
alert("无cookie值")
}
}
标签:
原文地址:http://my.oschina.net/u/2421889/blog/490749