为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我点一键换肤没有反应

<!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>


正在回答

2 回答

错误地方:

function newColor()

{

// alert("年后");

var newUl=document.getElementById("hh");

newul.className="h";

}

原:newul.className="h";

改:newUl.className="h";

原因:其实,你就是把变量的名字写错了而已。。(这里我只能感叹一句,命名规则很重要。)

0 回复 有任何疑惑可以回复我~
#1

唯尔半截湘妃 提问者

very much!我自己找了半天都没找到!
2016-07-08 回复 有任何疑惑可以回复我~

<!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>


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么我点一键换肤没有反应

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号