代码如下:
var Cookie = {
get : function(name){
var value = "";
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) { value=unescape(arr[2]); }
return value;
},
set : function(name,value,days){
if(isNaN(days)){
document.cookie=name + "=" + escape(value) + ";";
}else{
document.cookie=name + "=" + escape(value) + ";expires="+new Date(new Date().getTime() + days*86400000).toGMTString();
}
},
del : function(name){
document.cookie=name + "=;expires="+new Date().toGMTString();
}
}
附带一个日期格式化方法:
/**//*
*对date对象增加format方法,可以获取当前时间到对象
*如:
*var date = new Date();
*date.Format("YYYY-MM-DD HH:MI:SS");返回:2008-01-25 14:30:01;
*date.Format("YYYY/MM/DD HH:MI:SS");返回:2008/01/25 14:30:01;
**/
Date.prototype.Format=function(str)
{
var year = this.getFullYear();
var month = (this.getMonth()+1)<10?"0"+(this.getMonth()+1):(this.getMonth()+1);
var day = this.getDate()<10?"0"+this.getDate():this.getDate();
var hour = this.getHours()<10?"0"+this.getHours():this.getHours();
var min = this.getMinutes()<10?"0"+this.getMinutes():this.getMinutes();
var sec = this.getSeconds()<10?"0"+this.getSeconds():this.getSeconds();
tmp = str.replace("YYYY",year);
tmp = tmp.replace("MM",month);
tmp = tmp.replace("DD",day);
tmp = tmp.replace("HH",hour);
tmp = tmp.replace("MI",min);
tmp = tmp.replace("SS",sec);
return tmp;
}