Home > Web Front-end > JS Tutorial > js cookie operations

js cookie operations

巴扎黑
Release: 2016-12-20 14:57:39
Original
1148 people have browsed it

function getCookie(name)...{
var value = document.cookie;
var arr1 = value.split(";");
for(i=0;i                                                                                                                                                                                  return arr1[i].split("=")[1];
                                                                                                                                              return cookie
  //Somewhat similar to an anonymous class
var expires = function()...{//The cookie expiration time is within 48 hours from creation
  var mydate = new Date();
  mydate.setTime(mydate. getTime + 48*60*60*1000);
                                                                                                                  ,,                             ,,   " = " + SVALUE +"; Expires = " + Expires;}} else ... {
Alert (" You fill in free! "); sName,sValue)...{//Delete a specified cookie key-value pair
Document.cookie = sName + "=" + escape(sValue) + ";expires=Fri, 31 Dec 1999 23:59:59 GMT; ";
}
/**//****************************************
Set cookie content
* ******************************************/
function DelCookie(sName)...{
var sValue=getCookie(sName);
if(sValue!=null)...{
document.cookie = sName + "=" + escape(sValue) + ";expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
}
/**//******************************************
Delete cookies
*** ****************************************/
function clearCookie()...{
var value = document.cookie;
var arr1 = value.split(";");
for(i=arr1.length-1;i>=0;i--)...{
if(value. length == 0) ... {
Break;
}
sname = Arr1 [i] .split ("=") [0]; document.cookie = sName + "=" + escape(sValue) + ";expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
}

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template