0

我正在制作 Div 的手风琴,这里是代码:

 $('.answer').hide();
 $('.question').click (function(){
    $('.answer').slideUp();
    $('#question'+$(this).attr('target')).slideDown('slow');
 })

它工作正常,但我想要它,所以当我再次点击同一个问题时它会关闭。
这是我使用的 HTML:

<h1 class="question" target="1">Some Question</h1>
<p id="question1" class="answer">Some Answer</p>
<h1 class="question" target="2">Another question</h1>
<p id="question2" class="answer">Another answer</p>

提前致谢

请看这里的代码:http: //jsfiddle.net/FMLhc/

4

1 回答 1

0

这有效:

http://jsfiddle.net/FMLhc/15/

基本上,只需检查切换的状态,然后做你需要做的事情。

于 2012-07-17T03:10:10.600 回答