我在jsfiddle: http://jsfiddle.net/yt88bsnf/1/中创建了这个例子
一部分显示为none,另一部分显示。我想要完成的是,当其中一个h2元素被单击时,下面的部分将显示(除非它已经显示,那么它将保持显示),而另一个h2元素显示更改为none(除非它已经显示为none)。
任何帮助或建议将不胜感激!由于HTML:<div id="container">
<h2>Section One</h2>
<h2>Section Two</h2>
</div>
<div id="section_one">
This is Section One
</div>
<div id="section_two">
This is Section Two
</div>
CSS:#container{
overflow:hidden;
}
#container h2{
float:left;
margin-right:30px;
cursor:pointer;
}
#section_two{
display:none;
}
检查这个
可以使用jquery的show()
和hide()
。有关更多信息,请参阅w3schools
文档见这里
- show () >
- 隐藏()
JS
$("#header1").click(function () {
$("#section_one").show();
$("#section_two").hide();
});
$("#header2").click(function () {
$("#section_two").show();
$("#section_one").hide();
});