日期:2014-05-16 浏览次数:20349 次
function $(obj){
return document.getElementById(obj);
}
var skin={};
skin.addEvent=function(){
var skins =$("skin").getElementsByTagName("li");
for (i=0;i<skins.length;i++)
{
skins[i].onclick=function(){skin.setSkin(this.id.substring(5))};
}
}
skin.setCookie=function(n){
var expires=new Date();
expires.setTime(expires.getTime()+24*60*60*365*1000);
var flag="Skin_Cookie="+n;
document.cookie=flag+";expires="+expires.toGMTString();
}
skin.readCookie=function(){
var skin=0
var mycookie=document.cookie;
var name="Skin_Cookie";
var start1=mycookie.indexOf(name+"=");
if(start1==-1){
skin=0;
}
else{
var start=mycookie.indexOf("=",start1)+1;
var end=mycookie.indexOf(";",start);
if(end=-1){
end=mycookie.length;
}
var values= unescape(mycookie.substring(start,end));
if (values!=null)
{
skin=values;
}
}
return skin;
}
skin.setSkin=function(n){
var skins =$("skin").getElementsByTagName("li");
for (i=0;i<skins.length;i++)
{
skins[i].className="";
}
skin.setCookie(n);
$("skin_"+n).className="selected";
$("cssfile").href="css/main"+n+".css";
}
window.onload=function(){
skin.setSkin(skin.readCookie());
skin.addEvent();
}
<!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 runat="server">
<title>换肤</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link href="css/main0.css" rel="stylesheet" type="text/css" id="cssfile" />
<script language="JavaScript" src="javascript/skin.js" type="text/javascript"></script>
</head>
<body>
<ul id="skin">
<li id="skin_0" title="灰色">灰色</li>
<li id="skin_1" title="绿色">绿色</li>
<li id="skin_2" title="黄色">黄色</li>
<li id="skin_3" title="蓝色">蓝色</li>
<li id="skin_4" title="粉色">粉色</li>
<li id="skin_5" title="紫色">紫色</li>
</ul>
<div id="div_side_0">
<div id="news">
<h1 class="title">标题1</h1>
<div id="news_list"> </div>
</div>
</div>
<div id="div_side_1">
<div id="game">
<h1 class="title">标题2</h1>
<div id="game_list"> </div>
</div>
</div>
<div id="div_side_2">
&n