我有以下的jsfiddle:格显示基于按钮
测试按钮的第一组(“表现出来”和“隐藏”)工作的伟大。我一直在尝试获得第二组按钮(“有它”和“需要它”)以对div做同样的事情。不工作。有什么建议么?另外,如果那里有一个更有效的方式做到这一点...
这里从小提琴代码:
<!DOCTYPE html>
<html>
<head>
<style>
p { background:yellow; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<button class="1">Show it</button>
<button class="2">Hide it</button>
<p style="display: none" class="1">Hello</p>
<p style="display: none" class="2">Un Hello!</p>
<script>
$("button.1").click(function() {
$("p.1").show("slow");
$("p.2").hide("fast");
});
</script>
<script>
$("button.2").click(function() {
$("p.1").hide("fast");
$("p.2").show("slow");
});
</script>
<button class="have">Have</button>
<button class="need">Need</button>
<div id="have" style="display: none">HAVE YO</div>
<div id="need" style="display: none">NEED YO</div>
<script>
$("button.have").click(function() {
$("div.have").show("slow");
$("div.need").hide("fast");
});
</script>
<script>
$("button.need").click(function() {
$("div.need").show("slow");
$("div.have").hide("fast");
});
</script>
</body>
</html>