cookie读写应用

    技术2022-05-11  186

    <script language="javascript"> <!--Hide script from older browsers function loadUser() {     var cookieName="";     var cookieValue="";     cookieName=document.all.name2.value;     cookieValue=readCookie(cookieName);     if(cookieValue!='')       document.all.name4.value=cookieValue; } function saveCookie() {     var cName=document.all.name2.value;     var cValue=document.all.name4.value;     setCookie(cName,cValue); } function setCookie(name,value) {   date=new Date();   date.setMonth(date.getMonth()+6);   document.cookie=name+"="+escape(value)+"; expires=" + date.toGMTString(); } function readCookie(name) {   //if there is no cookie,return false,else return the value.   if(document.cookie=='')      return false;    else      return unescape(getCookieValue(name)); } function getCookieValue(name) {    //Declare variables.    var firstChar,lastChar;    //Get the entire cookie string.    var theBigCookie=document.cookie;    //alert(theBigCookie);    firstChar=theBigCookie.indexOf(name);    if(firstChar!=-1)    {      firstChar+=name.length+1;   lastChar=theBigCookie.indexOf(';',firstChar);   if(lastChar==-1)lastChar=theBigCookie.length;   return theBigCookie.substring(firstChar,lastChar);    }    else    return false; } //end hiding javascript -->

    最新回复(0)