1、设置cookie(名称,值,过期时间)
function setCookie(key,value,d){
if(d === undefined){
document.cookie = encodeURIComponent(key) + "=" + encodeURIComponent(value);
}else{
document.cookie = encodeURIComponent(key) + "=" + encodeURIComponent(value) + ";max-age=" + (d*60*60*24);
}
}
2、查找cookie(名称)
function getCookie(key){
var arr1 = document.cookie.split("; ");
for(var i = 0; i < arr1.length; i++){
var arr2 = arr1[i].split("=");
if(arr2[0] == key){
return decodeURIComponent(arr2[1]);
}
}
}