jquery - 下拉导航菜单打开内部菜单

时间:2012-12-24 09:20:40

标签: jquery

我无法处理内部菜单,只有外部菜单打开正常 任何人都知道如何处理它?<​​/ p>

HTML:

<nav id="menu-nav">
        <ul>
            <li class="top">
                <a href="#">Reports</a>
                <ul>
                    <li>
                        <a href="#">Credit Balance</a>
                        <ul>
                            <li>Sales</li>
                            <li>Float Credit</li>
                            <li>Consumed Credit</li>
                        </ul>
                    </li>
                    <li>
                        <a href="#">Calls</a>
                        <ul>
                            <li>Client Calls</li>
                            <li>Expert Calls</li>
                            <li>Current Calls</li>
                            <li>Errors</li>
                        </ul>
                    </li>
                    <li>
                        <a href="#">Users/Experts</a>
                        <ul>
                            <li>Users Report</li>
                            <li>Expertest Report</li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li class="top">
                <a href="#">Support</a>
                <ul>
                    <li>New Tickets</li>
                    <li>Open Tickets</li>
                    <li>Archived Tickets</li>
                </ul>
            </li>
            <li>User Management</li>
            <li>Packages Managments</li>
            <li class="top">
                <a href="#">Application Managments</a>
                <ul>
                    <li>Notification Manager</li>
                    <li>Application Settings</li>
                </ul>
            </li>
        </ul>
    </nav>

jQuery的:

$(document).ready(function() {
    $("#menu-nav").click(function(e){
        e.stopPropagation(); // this stops the bubbling from going any higher
    });
    $('body').click(function(){ // this is only reached if the clicks comes outside the #menu-nav
        $("#menu-nav ul ul").slideUp('fast');
    });
    $("#menu-nav ul li.top").click(function() {
        $("#menu-nav ul ul").slideUp("fast", function(){});

        $("ul:first", this).slideDown("fast", function(){
            $("ul", this).slideUp("fast");
        });
    });
});

1 个答案:

答案 0 :(得分:4)

请参阅:http://jsfiddle.net/5ehK6/2/

$(document).ready(function() {
$("#menu-nav").click(function(e) {
    e.stopPropagation(); // this stops the bubbling from going any higher
});
$('body').click(function(){ // this is only reached if the clicks comes outside the #menu-nav
    $("#menu-nav ul ul").slideUp('fast');
});
$("#menu-nav ul ul").hide();
$("#menu-nav ul li.top li").click(function() {
    $("#menu-nav ul ul ul").slideUp("fast", function() {});

    $("ul:first", this).slideDown("fast", function() {
        $("ul", this).slideUp("fast");
    });
    return false;
});
$("#menu-nav ul li.top").click(function() {
    $("#menu-nav ul ul").slideUp("fast", function() {});

    $("ul:first", this).slideDown("fast", function() {
        $("ul", this).slideUp("fast");
    });
    return false;
});
});​