我想知道我应该怎么做才能用同一个类名显示多个div中的一个div。如果一个人打开,我点击另一个,打开的那个应该关闭,而我点击的那个应该打开。如何找到具有相同类名的其他divs并关闭它们
HTML:
<div class="out">
<div class="content"> <a>click here to learn more..</a>
</div>
</div>
<div class="out">
<div class="content"> <a>click here to learn more..</a>
</div>
</div>
<div class="out">
<div class="content"> <a>click here to learn more..</a>
</div>
</div>
CSS:
.out {
width:150px;
height: 25px;
background-color: green;
float: left;
margin-right:10px;
}
.open {
border-bottom:5px solid peru;
height: 150px;
}
.out.open .content {
width:100%;
height:100%;
}
a {
display: none;
}
.open .content {
display: block;
}
.open .content > a {
color: white;
text-decoration: underline;
display: block;
}
JS:
$(document).ready(function() {
$('.out').click(function() {
$('.out').find('open').removeClass('open');
$(this).addClass('open');
});
});
我知道这个问题是在jQuery的,但我有没有什么我线索做错了。
这里有一个小提琴太:http://jsfiddle.net/4hpgb/22/
是的这几乎完美的作品,我唯一的问题是,为什么有一个'函数(我,五)?我和v代表什么? 而另一个问题,当我再次点击该div时,它将不会关闭。 – Jeroen
代表索引和值,只是写他们显示语法,在这段代码中不需要它,并且你没有说关闭行为再次登录div –
确实,@ nouphal.M但它不是你的错。我只是忘了提及它。 – Jeroen