【问题标题】:jQuery Accordion Collapse and Expand Issue (Parent & Child)jQuery Accordion 折叠和展开问题(父子)
【发布时间】:2011-12-28 22:15:30
【问题描述】:

我正在使用 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】:

    您想利用父手风琴的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/

    【讨论】:

    • 我能再问你一件事吗???你知道一旦你在那个页面上如何禁用链接吗??
    • 我想我找到了 jQuery("a[href$='" + path + "']").removeAttr('href');谢谢你的帮助,安德鲁。
    • @user1118445:没问题!如果有帮助请“接受”答案:)
    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 2011-04-21
    • 2011-02-02
    • 2011-12-18
    • 2011-06-25
    • 2022-11-19
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多