為什么我點一鍵換膚沒有反應
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{margin:0; pading:0;}
.dh{ height:30px; width:800px; list-style: none; background: red;}
.dh li a{
display: block;
float:left;
height:30px;
line-height:30px;
width:100px;
background: #fc6;
text-align: center;
color:green;
text-decoration:none;
}
.dh li a:hover{
background: #DBE6FD;
color:#999;
}
.h{ height:30px; width:700px; list-style: none;}
.h li a{
display: block;
float:left;
height:30px;
line-height:30px;
width:100px;
background:#E3E0D5;
text-align: center;
color:green;
text-decoration:none;
}
.h li a:hover{
background: #DBE6FD;
color:#999;
}
? ? }
</style>
</head>
<body>
<ul id="hh">
<li><a href="#">首頁</a></li>
<li><a href="#">新聞</a></li>
<li><a href="#">音樂</a></li>
<li><a href="#">貼吧</a></li>
<li><a href="#">知道</a></li>
<li><a href="#">政治</a></li>
<li><a href="#">經濟</a></li>
</ul>
<input type="button" value="一鍵換膚" onclick="newColor()"/>
<script type="text/javascript">
function newColor()
{
// alert("年后");
var newUl=document.getElementById("hh");
newul.className="h";
}
</script>
</body>
</html>
2016-07-07
錯誤地方:
function newColor()
{
// alert("年后");
var newUl=document.getElementById("hh");
newul.className="h";
}
原:newul.className="h";
改:newUl.className="h";
原因:其實,你就是把變量的名字寫錯了而已。。(這里我只能感嘆一句,命名規則很重要。)
2016-07-06
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{margin:0; pading:0;}
.dh{ height:30px; width:800px; list-style: none; background: red;}
.dh li a{
display: block;
float:left;
height:30px;
line-height:30px;
width:100px;
background: #fc6;
text-align: center;
color:green;
text-decoration:none;
}
.dh li a:hover{
background: #DBE6FD;
color:#999;
}
.h{ height:30px; width:700px; list-style: none;}
.h li a{
display: block;
float:left;
height:30px;
line-height:30px;
width:100px;
background:#E3E0D5;
text-align: center;
color:green;
text-decoration:none;
}
.h li a:hover{
background: #DBE6FD;
color:#999;
}
? ? }
</style>
</head>
<body>
<ul id="hh" class="dh">
<li><a href="#">首頁</a></li>
<li><a href="#">新聞</a></li>
<li><a href="#">音樂</a></li>
<li><a href="#">貼吧</a></li>
<li><a href="#">知道</a></li>
<li><a href="#">政治</a></li>
<li><a href="#">經濟</a></li>
</ul>
<input type="button" value="一鍵換膚" onclick="newColor()"/>
<script type="text/javascript">
function newColor()
{
// alert("年后");
var newUl=document.getElementById("hh");
newul.className="h";
}
</script>
</body>
</html>