A. Cookies
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8">5 <title></title>6 </Head>7 <Body>8 <inputtype= "text"name= "username"ID= "username"value="">9 <inputtype= "Password"name= "Password"ID= "Password"value="">Ten <Buttontype= "button"name= "button"ID= "BTN">Delete Cookies</Button> One <Scripttype= "Text/javascript"> A //1. Set up, get - varD= NewDate (); - d.sethours (d.gethours ()+ 1);//expires after 1 hours the //path=/This cookie can be accessed by all directories in the site at this time/on behalf of - Document.cookie='username=zhangsan;expires='+d.toutcstring ()+";p ath=/";//Set Cookies - Document.cookie;//get all the cookies - Console.log (Document.cookie) + - //2. Setting, acquiring, and deleting cookies + //setcookie (' Password ', ' 123456 ', 0.5*3600*1000)//30 minutes after expiration A //Setcookie (' username ', ' Zhangsan ', 0.5*3600*1000)//expires in 30 minutes at varBtnobj=document.getElementById ('btn') - Btnobj.onclick= function(){ - Delcookie ('username'); - Delcookie ('Password'); - } - functionSetcookie (name,value,expires) { in //Calculate Validity period - varD= NewDate (); to //Set Validity period + D.settime (D.gettime ()+expires); - //Set Cookies the Document.cookie=name+'='+value+'; expires='+d.toutcstring (); * } $ functionGetCookie (name) {Panax Notoginseng //Get Cookies - varcookiestr=Document.cookie; the //to divide or divide + varCookiearr=Cookiestr.split (';'); A //get the corresponding cookie value the name+= '=';//The cookie value obtained is followed by = + varresult= "'; - for(varI=0; I<Cookiearr.length;i++) { $ //not a cookie is worth a space before, remove the space, and then find the corresponding name value $ vartmp=Cookiearr[i].trim (); - if(Tmp.indexof (name)== 0) { - //If the lookup succeeds, return directly to the the result=Tmp.slice (name.length); - Break;Wuyi } the } - //return Results Wu returnresult; - } About functionDelcookie (name) { $ varD= NewDate (); - D.settime (D.gettime ()- +); - Document.cookie=name+'=;expires='+d.toutcstring (); - } A </Script> + </Body> the </HTML>
JS in cookies, Sessionstorage, localstorage