The following is an article from abroad.
Http://www.jb51.net/article/20553.htm
Copy codeThe Code is as follows:
Var sel = new Object ();
Var sel_num = 0;
Function getCookieVal (offset ){
Var endstr = document. cookie. indexOf (";", offset );
If (endstr =-1) endstr = document. cookie. length;
Return unescape (document. cookie. substring (offset, endstr ));
}
Function GetCookie (name ){
Var arg = name + "= ";
Var alen = arg. length;
Var clen = document. cookie. length;
// Alert (document. cookie. length );
Var I = 0;
While (I <clen ){
Var j = I + alen;
If (document. cookie. substring (I, j) = arg)
Return getCookieVal (j );
I = document. cookie. indexOf ("", I) + 1;
If (I = 0) break;
}
Return null;
}
Function SetCookie (name, value, expires, path, domain, secure ){
Document. cookie = name + "=" + escape (value) + (expires )? "; Expires =" + expires. toGMTString (): "") + (path )? "; Path =" + path: "") + (domain )? "; Domain =" + domain: "") + (secure )? "; Secure ":"");
Return value;
}
Function DeleteCookie (name ){
If (GetCookie (name )! = Null ){
SetCookie (name, "", null, "/", null );
}
}
Function cookie_content (){
I = 0;
Var content = "";
For (key in sel ){
If (I = 0 ){
Content + = key + "[" + sel [key] + "]";
}
Else {
Content + = "," + key + "[" + sel [key] + "]";
} I ++;
}
Return content;
}
Function inni_data (){
Var cookie_sel = new Object ();
Cookie_str = GetCookie ("Member_COOKIE ");
If (cookie_str! = "" & Cookie_str! = Null ){
Cookie_sel = cookie_str.split (',');
For (var k = 0; k <cookie_sel.length; k ++ ){
I = cookie_sel [k]. indexOf ("[");
J = cookie_sel [k]. indexOf ("]");
Sel [cookie_sel [k]. substring (0, I)] = cookie_sel [k]. substring (I + 1, j );
Sel_num ++;
}
Draw ();
}
}
Function addMember (id, nm ){
If (! Sel [id]) {
Sel_num ++; sel [id] = nm;
}
Else
{Sel [id] = nm ;}
SetCookie ("Member_COOKIE", cookie_content (), null, "/", null );
}
Function draw (){
Out = '';
For (key in sel ){
$ ("#" + Key). val (sel [key]);
}
}