[技术]

CSS换颜色.。

日期:2008-03-06 16:45:50 天气:晴 字体:

<!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=gb2312" />
<title>无标题文档</title>
<link id="cssfile" href="style2.css" rel="stylesheet" type="text/css" />
</head>
<script>
// *** Cookies ***
function setCookie(name,value)
{
    var Days = 30;
    var exp  = new Date();    //new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^&line; )"+name+"=([^;]*)(;&line;)");
        if(arr=document.cookie.match(reg)) return unescape(arr[2]);
        else return null;
}

 function changeStyle(name){
  setCookie("cssStyle",name);
  css=document.getElementById("cssfile");
  css.href=name+".css";
 }
 
 var varcss = getCookie("cssStyle");
 changeStyle(varcss);
</script>
<body>
<div >
<a onclick="changeStyle('style1');" href="#" id="d1" >aaa</a>
<a onclick="changeStyle('style2');" href="#" id="d2" >bbb</a>
</div>
</body>
</html>

样式1
body {
background-color: #f00;
}
#d1{ font-size: 28px;}


样式2
body {
 background-color: #330099;
}
#d2{ font-size: 18px;}

评论(0) | 阅读(0) | 分类:技术 | 技术RSS | 最后更新:2009-02-07 16:45:50
  • 昵 称: (必填)
  • QQ 号: (必填)
  • 评 论: (必填5-250字)
  • 验证码: (必填) 验证码
关于lijun友情链接赣ICP备2022005502号