jQuery手风琴折叠和展开问题(父母和孩子)

问题描述 投票:1回答:1

我正在使用jQuery Accordion菜单,发现父子导航存在问题,需要紧急帮助,谢谢

我完全展开了一个父菜单及其子菜单,然后单击标题以使其折叠。然后我展开另一个标题,当我返回单击第一个标题时,子菜单未折叠。选择另一个父标题时,是否可以折叠一个父的所有子标题?

感谢:)

这是我的代码

<div id="accordion">
    <h3><a>Link One - First Level</a></h3>
    <div class="accordionSecond">      
        <h6><a href="#">Second Level</a></h6>
        <div class="accordionLink"> 
        <a href="1.html">1.html</a>
        <a href="2.html">2.html</a>
        <a href="3.html">3.html</a>
        <a href="4.html">4.html</a>
        </div>
    </div>

    <h3><a>Link Two - First Level</a></h3>
    <div class="accordionSecond">      
        <h6><a href="#">Second Level</a></h6>
        <div class="accordionLink"> 
        <a href="1.html">1.html</a>
        <a href="2.html">2.html</a>
        <a href="3.html">3.html</a>
        <a href="4.html">4.html</a>
        </div>
    </div>    

</div>   

这是小脚本行

  <script>
  $(document).ready(function() {
    $("#accordion").accordion( {active: true,  collapsible: true, header: "h3", autoHeight: false, navigation: true, event: 'mouseup'}); 
    $(".accordionSecond").accordion( {active: true,  collapsible: true, header: "h6", autoHeight: false, navigation: true,event: 'mouseup'});
  });
  </script>
jquery jquery-ui jquery-ui-accordion
1个回答
2
投票

您想利用父手风琴的changestart事件。在这里,您可以折叠任何儿童手风琴:

$("#accordion").accordion({
    active: true,
    collapsible: true,
    header: "h3",
    autoHeight: false,
    navigation: true,
    event: 'mouseup',
    changestart: function (event, ui) {
        ui.oldContent.accordion("activate", false);
    }
});

使用activate方法并将其传递给false会告诉手风琴折叠所有部分。

示例: http://jsfiddle.net/p2h8V/

© www.soinside.com 2019 - 2024. All rights reserved.