The following is a foreign Article Article .
Http://www.jb51.net/article/20553.htm
CopyCode The 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]);
}
}