![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title > 无标题文档 </ title >
< link rel ="stylesheet" id ="color" type ="text/css" href ="Color.css" />
< script type ="text/javascript" >
function getObject(elementId){
if (document.getElementById(elementId)){
return document.getElementById(elementId);
} else if (document.all){
return document.all[elementId];
} else if (document.layers){ // NetSpace
return document.layers[elementId];
}
}
function changeStyle(id){ // 切换样式
var stylesheet = getObject( " color " ).href = " Color " + id + " .css " ;
document.cookie = " stylesheet= " + escape(stylesheet); // 写入Cookie
// alert(document.cookie);
// alert(stylesheet);
}
function initStyle(){
if ( / stylesheet=([^;]+) / .test(document.cookie)){ // 判断是否存在cookie
getObject( " color " ).href = unescape(RegExp.$ 1 );
}
// alert(/stylesheet=[^;]+/.test(document.cookie));
}
initStyle();
</ script >
</ head >
< body >
< a onclick ="changeStyle(1)" href ="#" > 样式1 </ a >
< a onclick ="changeStyle(2)" href ="#" > 样式2 </ a >
< div id ="h" ></ div >
< div id ="c" ></ div >
< div id ="f" ></ div >
</ body >
</ html >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< title > 无标题文档 </ title >
< link rel ="stylesheet" id ="color" type ="text/css" href ="Color.css" />
< script type ="text/javascript" >
function getObject(elementId){
if (document.getElementById(elementId)){
return document.getElementById(elementId);
} else if (document.all){
return document.all[elementId];
} else if (document.layers){ // NetSpace
return document.layers[elementId];
}
}
function changeStyle(id){ // 切换样式
var stylesheet = getObject( " color " ).href = " Color " + id + " .css " ;
document.cookie = " stylesheet= " + escape(stylesheet); // 写入Cookie
// alert(document.cookie);
// alert(stylesheet);
}
function initStyle(){
if ( / stylesheet=([^;]+) / .test(document.cookie)){ // 判断是否存在cookie
getObject( " color " ).href = unescape(RegExp.$ 1 );
}
// alert(/stylesheet=[^;]+/.test(document.cookie));
}
initStyle();
</ script >
</ head >
< body >
< a onclick ="changeStyle(1)" href ="#" > 样式1 </ a >
< a onclick ="changeStyle(2)" href ="#" > 样式2 </ a >
< div id ="h" ></ div >
< div id ="c" ></ div >
< div id ="f" ></ div >
</ body >
</ html >