The first is JavaScript code:
Function setactivestylesheet (title ){
VaR I, A, main;
For (I = 0; (a = Document. getelementsbytagname ("Link") [I]); I ++ ){
If (A. getattribute ("rel"). indexof ("style ")! =-1 & A. getattribute ("title ")){
A. Disabled = true;
If (A. getattribute ("title") = title) A. Disabled = false;
}
}
}
Function getactivestylesheet (){
VaR I,;
For (I = 0; (a = Document. getelementsbytagname ("Link") [I]); I ++ ){
If (A. getattribute ("rel"). indexof ("style ")! =-1 & A. getattribute ("title ")&&! A. Disabled) return a. getattribute ("title ");
}
Return NULL;
}
Function getpreferredstylesheet (){
VaR I,;
For (I = 0; (a = Document. getelementsbytagname ("Link") [I]); I ++ ){
If (A. getattribute ("rel"). indexof ("style ")! =-1
& A. getattribute ("rel"). indexof ("Alt") =-1
& A. getattribute ("title ")
) Return a. getattribute ("title ");
}
Return NULL;
}
Function createcookie (name, value, days ){
If (days ){
VaR date = new date ();
Date. settime (date. gettime () + (days * 24x60*60*1000 ));
VaR expires = "; expires =" + date. togmtstring ();
}
Else expires = "";
Documents. Cookie = Name + "=" + value + expires + "; Path = /";
}
Function readcookie (name ){
VaR nameeq = Name + "= ";
VaR CA = documents. Cookie. Split (';');
For (VAR I = 0; I <ca. length; I ++ ){
VaR c = Ca [I];
While (C. charat (0) = '') C = C. substring (1, C. Length );
If (C. indexof (nameeq) = 0) return C. substring (nameeq. length, C. Length );
}
Return NULL;
}
Window. onload = function (e ){
VaR cookie = readcookie ("style ");
VaR Title = cookie? COOKIE: getpreferredstylesheet ();
Setactivestylesheet (title );
}
Window. onUnload = function (e ){
VaR Title = getactivestylesheet ();
Createcookie ("style", title, 365 );
}
VaR cookie = readcookie ("style ");
VaR Title = cookie? COOKIE: getpreferredstylesheet ();
Setactivestylesheet (title );
Then introduce all the style sheets to the document:
<LINK rel = "stylesheet" type = "text/CSS" href = "css.css"/>
<LINK rel = "stylesheet" type = "text/CSS" href = "aaa.css" Title = "AAA"/>
<LINK rel = "stylesheet" type = "text/CSS" href = "bbb.css" Title = "BBB"/>
The button for switching the style is as follows:
<A href = "#" onclick = "setactivestylesheet ('', 1); Return false; "> default style-white </a>
<A href = "#" onclick = "setactivestylesheet ('aaa', 1); Return false;"> style 1-blue </a>
<A href = "#" onclick = "setactivestylesheet ('bbb ', 1); Return false;"> style 2-orange </a>