标签:style blog color io java ar for div sp
在其他人都开会到时间里,我偷偷摸哦的试了一下cookie,唉,从来没有用过cookie,慢慢的知识忘光了,还好这次偷偷摸摸的做出来了,虚,大家都别出声啊
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>cookie</title> </head> <body> <input type="text" /> <input type="text" /> <input type="submit" /> <button>释放cookie</button> </body> </html> <script type="text/javascript"> var t=document.getElementsByTagName("input")[0]; var p=document.getElementsByTagName("input")[1]; var b=document.getElementsByTagName("input")[2]; var bb=document.getElementsByTagName("button")[0]; bb.onclick=function(){ alert(getCookie("password")); } b.onclick=function(){ var n=t.value; var s=p.value; setCookie("username",n,5000) setCookie("password",s,5000) delCookie("username") } function setCookie(n,v,t){//n==name,v==value,t=time(毫秒) var d=new Date(); d.setTime(d.getTime()+t); document.cookie=n+"="+escape(v)+" ;expires="+d.toGMTString(); } function getCookie(n){ if(document.cookie){ var c=document.cookie; var a=c.split("; "); for(var i=0;i<a.length;i++){ var aa=a[i].split("="); if(aa[0]==n){ return aa[1]; } } } } function delCookie(n){//n==name setCookie(n,null,-100) } </script>
标签:style blog color io java ar for div sp
原文地址:http://www.cnblogs.com/busicu/p/3979431.html