我想在点击菜单时隐藏其他菜单项

时间:2013-06-26 22:28:59

标签: javascript jquery html asp.net jquery-ui

我试图找出如何隐藏菜单中的其他子菜单项。现在,当点击两个菜单时,它们都显示,我不想要。

<script type="text/javascript" src="jquery/js/jquery-1.9.1.js"></script>
<script src="jquery/js/jquery-ui-1.10.3.custom.js"></script>
<script>
jQuery(function ($) {
    $(".accordion").accordion({
        active: false,
        autoHeight: false,
        collapsible: true,
        alwaysOpen: false
    });

    function collapseAll() {
        $("#accordion")
            .filter(":has(.ui-state-active)")
            .accordion("activate", -1);
        $(".ui-accordion-header").blur();

    }
});

 <div class="navigation">
    <ul class="accordion">
        <li>
            <asp:HyperLink ID="about" runat="server" href="#" text="testing" />
            <div class="sub accordion">
                <ul>
                    <li><asp:HyperLink ID="aboutTraci" runat="server" NavigateUrl="traci.aspx" Text="Traci" /></li>
                    <li><asp:HyperLink ID="aboutTheBegan" runat="server" NavigateUrl="#" Text="How It All Began" /></li>
                    <li><asp:HyperLink ID="aboutDesigners" runat="server" NavigateUrl="#" Text="Designers" /></li>
                    <li><asp:HyperLink ID="aboutPlaygroup" runat="server" NavigateUrl="#" Text="Playgroup" /></li>
                    <li><asp:HyperLink ID="aboutPlayground" runat="server" NavigateUrl="#" Text="Playground" /></li>
                    <li><asp:HyperLink ID="aboutTestimonials" runat="server" NavigateUrl="testimonials.aspx" Text="Testimonials" /></li>
                </ul>
            </div>
        </li>
    </ul>
    <ul class="accordion">
        <li>
            <asp:HyperLink ID="HyperLink1" runat="server" href="#" Text="testing" />
            <div class="sub accordion">
                <ul>
                    <li><asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="traci.aspx" Text="Traci" /></li>
                    <li><asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="#" Text="How It All Began" /></li>
                    <li><asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="#" Text="Designers" /></li>
                    <li><asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="#" Text="Playgroup" /></li>
                    <li><asp:HyperLink ID="HyperLink6" runat="server" NavigateUrl="#" Text="Playground" /></li>
                    <li><asp:HyperLink ID="HyperLink7" runat="server" NavigateUrl="testimonials.aspx" Text="Testimonials" /></li>
                </ul>
            </div>
        </li>
    </ul>
</div>

我想在点击其中时隐藏其他菜单项。

谢谢

1 个答案:

答案 0 :(得分:0)

要在单击其他菜单项时隐藏其他菜单项,您必须以一种手风琴api可以通过添加标题来理解它的方式构建您的html:example fiddle

<ul class="accordion">
        <li>
            <h3>Section 1</h3>
            <ul class="accordion">
                <li>
                    <h4> Link 1</h4><p>content</p>
                </li>
                <li>
                    <h4> Link 2</h4><p>content</p>
                </li>
                <li>
                    <h4> Link 3</h4><p>content</p>
                </li>
            </ul>
        </li>
        <li>
            <h3>Section 2</h3>
            <ul class="accordion">
                <li>
                    <h4> Link 1</h4><p>content</p>
                </li>
                <li>
                    <h4> Link 2</h4><p>content</p>
                </li>
                <li>
                    <h4> Link 3</h4><p>content</p>
                </li>
            </ul>
        </li>
    </ul>