zl程序教程

您现在的位置是:首页 >  后端

当前栏目

js动态修改整个页面样式达到换肤效果

JS 修改 动态 页面 效果 样式 达到 整个
2023-06-13 09:15:27 时间
jsPro1\js动态修改整个html页面样式(换肤).html
复制代码代码如下:

<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>动态修改页面样式</title>
<linkhref="css/blue.css"rel="stylesheet"id="mylink"/>
<scripttype="text/javascript">
functiongel(id){
returndocument.getElementById(id);
}

window.onload=function(){
//更换css文件
varlis=gel("uList").childNodes;
for(vari=0;i<lis.length;i++){
if(lis[i].nodeType==1){
lis[i].onclick=function(){
gel("mylink").href="css/"+this.className+".css";
};
}
}
};

</script>
</head>

<body>
<div>
<span>修改整个页面的样式</span><br/>
<inputtype="text"id="txt"/>
<inputtype="button"value="提交"class="btn"/>
</div>

<ulid="uList"style="text-decoration:none;margin-top:100px;">
<listyle="display:block;width:30px;height:20px;background-color:red;"class="red"></li>
<listyle="display:block;width:30px;height:20px;background-color:blue"class="blue"></li>
</ul>
</body>
</html>

jsPro1\css\red.css
复制代码代码如下:

*{
margin:0px;padding:0px;
}


body{
background-color:#eeeeee;
}
span{
color:red;
}
#txt{
color:#f00;border:1pxsolid#7d1515;
}
.btn{
background-color:#a52a2a;border:none;color:white;width:100px;height:28px;
}

jsPro1\css\blue.css
复制代码代码如下:
*{
margin:0px;padding:0px;
}


body{
background-color:#eeeeee;
}
span{
color:blue;
}
#txt{
color:#0000cd;border:1pxsolid#006400;
}
.btn{
background-color:#0000cd;border:none;color:white;width:100px;height:28px;
}