ringa_lee2017-04-10 14:31:42
function setCookie(key,value,options){
var options = options||{};
if(options.hour){
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + options.hour * 3600000);
}
window.document.cookie =
key + "=" + value
+ (options.path ? "; path=" + options.path : "")
+ (options.hour ? "; expires=" + expire.toGMTString() : "")
+ (options.domain ? "; domain=" + options.domain : "");
return this;
}
function getCookie(key){
var reg = new RegExp("(^| )" + key + "=([^;]*)(;|\x24)"),
result = reg.exec(document.cookie);
if(result){
return result[2]||null;
}
}
然后设置cookie的时间