I write a cookie set and get function, everyone has what feel need to improve the place, please inform me, I must humbly accept.
Code:
1 functionSetcookie (name,value,time) {2 if(name) {3 varDate =NewDate ();4 if(time) {5 varLastword = Time.slice (-1);6 Switch(Lastword) {7 Case' d ': Date.setdate (Date.getdate () +parseint (time)); Break;8 Case' H ': date.sethours (Date.gethours () +parseint (time)); Break;9 Case' m ': Date.setminutes (Date.getminutes () +parseint (time)); Break;Ten Case' s ': Date.setseconds (Date.getseconds () +parseint (time)); Break; One default: Date.setdate (date.getdate () +parseint (time)); A } - } -Document.cookie = Escape (name) + ' = ' + escape (value) +
"; expires=" + (time)? Date.togmtstring (): "); the } - } - - functionGetCookie (name) { + varCookie_value =Document.cookie; - varName =unescape (name); + varindex =Cookie_value.indexof (name); A if(index>=0){ at varLen =name.length; - varStart = Index+len+1; - varIsend = Cookie_value.indexof ('; '), start) - varEnd = (isend>=0)?isEnd:cookie_value.length; - returnunescape (cookie_value.substring (start,end)); - } in } - to /*parameter Description + * The name of the Name:cookie; - * The specific name of the Value:cookie; the * Time:cookie Expiration time, D indicates the number of days, H indicates the amount of time,
M represents minutes, s represents seconds, and if not specified, the default is the number of days * */
A cookie set and get function that you write yourself