div的手风琴

时间:2012-07-17 02:44:40

标签: jquery

我在这里制作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/

1 个答案:

答案 0 :(得分:0)

这有效:

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

基本上,只需检查切换的状态,然后执行您需要执行的操作。

相关问题