Home  >  Article  >  Web Front-end  >  Sample code for adding, obtaining, and deleting cookies in js_javascript skills

Sample code for adding, obtaining, and deleting cookies in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:19:171142browse
复制代码 代码如下:

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; ivar arr2 = arr[i].split("=");
if(arr2[0] == name){
return arr2[1];
}
}
return "";
}


function removeCookie(name){
setCookie(name,"",0)
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn