jQuery不能同时扩展这两个类

jQuery不能同时扩展这两个类,jquery,class,html,expand,Jquery,Class,Html,Expand,我有一些jQuery,当点击显示一个副标题时,它会展开一个div标题。再点击这个副标题,就会显示内容。不过,有两个副标题,我只能得到第一个 我尝试将选择器更改为上推荐的格式,但这只会导致页面加载时,副标题甚至没有隐藏。到目前为止,我得到的是: jQuery: <script type="text/javascript"> jQuery(document).ready(function() { jQuery(".subheadingFrame, .subheadingEngin

我有一些jQuery,当点击显示一个副标题时,它会展开一个div标题。再点击这个副标题,就会显示内容。不过,有两个副标题,我只能得到第一个

我尝试将选择器更改为上推荐的格式,但这只会导致页面加载时,副标题甚至没有隐藏。到目前为止,我得到的是:

jQuery:

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery(".subheadingFrame, .subheadingEngine").hide();
    jQuery(".heading").click(function()
    {
        jQuery(this).next(".subheadingFrame, .subheadingEngine").slideToggle(500);
    });
    jQuery(".content").hide();
    jQuery(".subheadingFrame, .subheadingEngine").click(function()
    {
        jQuery(this).next(".content").slideToggle(500);
    });
});
</script>

jQuery(文档).ready(函数(){
jQuery(“.subheadingFrame,.subheadingEngine”).hide();
jQuery(“.heading”)。单击(函数()
{
jQuery(this).next(“.subheadingFrame,.subheadingEngine”).slideToggle(500);
});
jQuery(“.content”).hide();
jQuery(“.subheadingFrame,.subheadingEngine”)。单击(函数()
{
jQuery(this).next(“.content”).slideToggle(500);
});
});
HTML:

Benelli1
框架/分目1
内容1
引擎/分目2
内容2
如果有人能帮忙,我已经把页面打开了。

试试这个

jQuery(".heading").click(function(){
        jQuery(this).nextAll(".subheadingFrame").first().slideToggle(500);
        jQuery(this).nextAll(".subheadingEngine").first().slideToggle(500);
});
.next()
仅针对.heading.的直接同级。。 因此,如果找不到它,它将返回一个空列表

因此,在这种情况下,最好使用
.nextAll()
.first()


谢谢Sushanth,我看到小提琴的工作原理与我希望的完全一样,但我已经仔细检查了我的代码,标题现在不再扩展(请参阅相关页面的链接)。部门id是否存在冲突?我在某个地方看到,可以通过jQuery(这个)定义类。nextAll(“#divID.subheadingFrame”)…?是页面上id的唯一性。。或者你有重复的id问题是你的页面上有重复的id。。因此,当您尝试通过id访问它时。。它只会得到第一个,因为ID在你的页面上应该是唯一的。。。想想jQuery(this).nextAll(“.subheadingFrame”).first()应该可以工作我的第一个html引用了…jQuery/1.3.2/jQuery.min.js,但我把它改成了…/1.8.2/。。。如小提琴所用。。。成功了!谢谢苏姗,你帮我省去了很多挫折@汉瑟。。很高兴能帮忙:)
jQuery(".heading").click(function(){
        jQuery(this).nextAll(".subheadingFrame").first().slideToggle(500);
        jQuery(this).nextAll(".subheadingEngine").first().slideToggle(500);
});