0

我试图弄清楚如何通过单击菜单来隐藏其他子菜单项。现在,当单击两个菜单时,它们都会显示,这是我不想要的。

<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>

单击一个菜单项时,我想隐藏其他菜单项。

谢谢

4

1 回答 1

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>
于 2013-06-27T11:25:19.190 回答