The following is an article abroad.
Http://www.jb51.net/article/20553.htm
Copy Code code 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]);
}
}