js换肤
代碼 <!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>無標(biāo)題文檔</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>無標(biāo)題文檔</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>
?
轉(zhuǎn)載于:https://www.cnblogs.com/jhxk/articles/1703691.html
總結(jié)
- 上一篇: 撒谎
- 下一篇: 用LINQ来对文章列表进行操作