js中cookie的添加、取值、删除示例代码
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:functionsetCookie(name,value,time){varoDate=newDate();oDate.s...
复制代码 代码如下:
function setCookie(name,value,time){
var oDate = new Date();
oDate.setDate(oDate.getDate()+time);
document.cookie = name+"="+value+";expires="+oDate;
}
function getCookie(name){
var arr = document.cookie.split("; ");
for(var i=0; i<arr.length; i++){
var arr2 = arr[i].split("=");
if(arr2[0] == name){
return arr2[1];
}
}
return "";
}
function removeCookie(name){
setCookie(name,"",0)
}