【发布时间】:2012-02-25 06:02:08
【问题描述】:
请看下面的代码sn-p -
HTML
<div class="aclass">
<h1>This is heading one</h1>
<p>This is paragraph one, this will be hidden automatically</p>
<p>This is paragraph two, this will be hidden automatically</p>
<p>This is paragraph three, this will be hidden automatically</p>
<h1>This is heading two</h1>
<p>This is paragraph four, this will be hidden automatically</p>
<p>This is paragraph five, this will be hidden automatically</p>
</div>
CSS
.aclass p {display:none;}
JS
$(document).ready(function(){
$('.aclass h1').click(function(){
$(this).next('p').toggle();
});
});
当点击 h1 标签时,此 JS 代码会切换在 h1 标签之后显示单个 p 标签。但我需要切换连续 p 标签的显示(点击标题一时为一到三个)
执行此操作的 jQuery 代码应该是什么?
【问题讨论】:
-
你应该将你的段落包装在一个 div 中,然后切换它。并不是说您的要求是不可能的,但它会比必要的复杂。
标签: jquery css-selectors