我废话少说。先贴出代码。
《xhtml》代码:
<!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>
<title>Jquery学习</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="index.css" />
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</head>
<body>
<div id="panel">
<h5 class="head">小山羊</h5>
<div class="content">
小山羊和小鸡是朋友,小鸡请小山羊吃虫子,小山羊说:“谢谢你,我不吃虫子”。小山羊和小狗是朋友,小狗请小山羊吃骨头。
小山羊说:“谢谢你,我不吃骨头”。小山羊和小猫是朋友,小猫请小山羊吃鱼,小山羊说:“谢谢你,我不吃鱼”。小山羊和小
牛是朋友,小牛请小山羊吃青草。小山羊说:“谢谢你”。小山羊和小牛一同吃青草。
</div>
</div>
</body>
</html>
《CSS》代码:
* {
margin:0;
padding:0;
}
#panel {
width:300px;
margin:0 auto;
margin-top:50px;
border:1px solid black;
}
#panel .head {
background:#ccc;
cursor:pointer;
}
#panel .content {
display:block;
display:none;
}
.head_back {
background:green;
}
《jquery代码》:
$(function() {
$("#panel .head").toggle(function() {
$("#panel .head").addClass("head_back");
$("#panel .content").show();
},function() {
$("#panel .head").removeClass("head_back")
$("#panel .content").hide();
})
})
效果就是:点击class为head,背景色由#ccc色变为绿色,并且显示class为content隐藏的内容。再点击head,则恢复原先的状态。为了方便大家明白我说的意思,我专门申请了个免费的网站,效果放在这个网址了:http://52web.host-ed.net (注意:本网站是在外国服务器上。所以如果无法连接,则是因为被和谐了。还有哈,找出问题之前,先别急看我的有效的源码哈)。
问题:class为content能显示。找找哪里出现了问题,使其class为head的背景色无法改为绿色?并说出原因。
注:问题我找出来了。就是不知道为什么要这样。
《xhtml》代码:
<!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>
<title>Jquery学习</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="index.css" />
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</head>
<body>
<div id="panel">
<h5 class="head">小山羊</h5>
<div class="content">
小山羊和小鸡是朋友,小鸡请小山羊吃虫子,小山羊说:“谢谢你,我不吃虫子”。小山羊和小狗是朋友,小狗请小山羊吃骨头。
小山羊说:“谢谢你,我不吃骨头”。小山羊和小猫是朋友,小猫请小山羊吃鱼,小山羊说:“谢谢你,我不吃鱼”。小山羊和小
牛是朋友,小牛请小山羊吃青草。小山羊说:“谢谢你”。小山羊和小牛一同吃青草。
</div>
</div>
</body>
</html>
《CSS》代码:
* {
margin:0;
padding:0;
}
#panel {
width:300px;
margin:0 auto;
margin-top:50px;
border:1px solid black;
}
#panel .head {
background:#ccc;
cursor:pointer;
}
#panel .content {
display:block;
display:none;
}
.head_back {
background:green;
}
《jquery代码》:
$(function() {
$("#panel .head").toggle(function() {
$("#panel .head").addClass("head_back");
$("#panel .content").show();
},function() {
$("#panel .head").removeClass("head_back")
$("#panel .content").hide();
})
})
效果就是:点击class为head,背景色由#ccc色变为绿色,并且显示class为content隐藏的内容。再点击head,则恢复原先的状态。为了方便大家明白我说的意思,我专门申请了个免费的网站,效果放在这个网址了:http://52web.host-ed.net (注意:本网站是在外国服务器上。所以如果无法连接,则是因为被和谐了。还有哈,找出问题之前,先别急看我的有效的源码哈)。
问题:class为content能显示。找找哪里出现了问题,使其class为head的背景色无法改为绿色?并说出原因。
注:问题我找出来了。就是不知道为什么要这样。
解决方案 »
- 判断radio是否选中的脚本不起作用
- 求助:帮忙看下代码!!!
- tablesortor如何对动态数据排序
- javascript自动构建table后,源文件发生了变化,且不再相应任何事件,请高手帮忙看看!
- 问js的简单问题...
- 1.break和return语句的区别是什么?
- 如何用正则表达式匹配一个整数!
- 请问为什么我的图片加上热点之后,周围会有一圈蓝色边框呢
- (急)Javascript如何将数据写入本地的记事本中???
- position:absolute是什么意思?
- 关于 window.onload 的问题
- 我用DW写了一个HTML+CSS的网页模板,在里面,我添加了谷歌的script广告代码,但是我本地测试浏览器打开老是被拦截,请问如何解决?
已经写了背景颜色颜色 。
添加head_back这个类 。但是还是取得head的背景色。
display:block;
display:none;
}
#panel .head_back {
background:green;
}因为css优先级别的问题
晕还是看不懂。我干脆改成这样了:
《CSS代码》:
* {
margin:0;
padding:0;
}
#panel {
width:300px;
margin:0 auto;
margin-top:50px;
border:1px solid black;
}
#panel .head {
background:#ccc;
cursor:pointer;
}
.content {
display:block;
display:none;
}
《jquery代码》:
$(function() {
$("#panel .head").toggle(function() {
$("#panel .head").css("background","green");
$("#panel .content").show();
},function() {
$("#panel .head").addClass("head")
$("#panel .content").hide();
})
})