控制CSS样式实现网页换肤的JS代码
2010-3-8 杜世伟 JavaScript
<!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>
</head>
<body>
<style id="red" disabled="ture">
body {
background-color:#f00;
}
</style>
<style id="blue" disabled="ture">
body {
background-color:#3399FF;
}
</style>
<style id="default">
body {
background-color:#fff;
}
</style>
<style type="text/css">
body {
font-size:12px;
font-family:Verdana, Arial, Helvetica, sans-serif;
margin:0;
}
</style>
</head>
<body>
<script>
function switchSkin(skin){
var style = document.getElementById(skin);
var tmp = document.getElementsByTagName('style');
var skinArr = [];
for(var i = 0; i < tmp.length; i++){
if(tmp[i].getAttribute('id')){
skinArr[i] = tmp[i].getAttribute('id');
document.getElementById(skinArr[i]).disabled = true;
}
}
style.disabled = false;
}
</script>
<input type="button" onclick="switchSkin('red');" value="red" />
<input type="button" onclick="switchSkin('blue');" value="blue" />
</body>
</html>
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(18)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(72)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)