//set a sub-cookie firstvarD =NewDate ();d. Setmonth (D.getmonth ()+ 1);d=d.togmtstring ();varA = "name:a, age:20, addr:beijing";varc = "user=" +Escape (a); C+ = ";" + "expires=" +D;document.cookie=C;//Read all cookie information, including the value of the child cookie information//return Value: Object (key: Each cookie variable "includes a key in a child cookie", value: The value of each cookie variable "includes the value in the child cookie")functionGetsubcookie () {varA = Document.cookie.split (";")); varo = {}; for(vari = 0; i < a.length; i++) {//iterating over cookie information arrayA[i] && (a[i] = A[i].replace (/(^\s*) | ( \s*$)/g, ")); //clear the head whitespace varb = a[i].split ("="); varc = b[1]; C&& (c = c.replace (/(^\s*) | ( \s*$)/g, ")); C=unescape (c); //If C does not contain a comma (not a child cookie), the value of C as a cookie variable is stored directly in the object if(!/\,/Gi.test (c)) {o[b[0]] = b[1]; }Else{ varD = C.split (","); for(varj=0; j<d.length; J + +){ varE = D[j].split (":"); e[0] && (e[0] = E[0].replace (/(^\s*) | ( \s*$)/g, ")); o[e[0]] = e[1]; } } } returno;}
JS function Collection: Get cookie value